Inital commit.
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
param (
|
||||
[string]$Path,
|
||||
[string]$Password,
|
||||
[int]$SpeedLimit=300,
|
||||
[switch]$SelfDestruct
|
||||
)
|
||||
|
||||
## Immediately delete this script from disk, if requested
|
||||
if ( $SelfDestruct ) {
|
||||
try { Remove-Item $MyINvocation.InvocationName -Force }
|
||||
catch { Write-Host "Self destruct failed, killing script!"; exit } }
|
||||
|
||||
## Download required tools
|
||||
$DOWNLOAD_TOOLS_SCRIPT = "https://emberkom.s3.amazonaws.com/management/scripts/Download-Tools.ps1"
|
||||
try { Invoke-Expression ((New-Object System.Net.WebClient).DownloadString($DOWNLOAD_TOOLS_SCRIPT)) }
|
||||
catch { Write-Host "Required tools failed to download!"; exit }
|
||||
|
||||
## Make sure WinSCP exists
|
||||
$WINSCP = "${Env:Temp}\Emberkom\Tools\winscp.com"
|
||||
if ( !(Test-Path "${WINSCP}") ) {
|
||||
if ( Test-Path "${Env:ProgramData}\Emberkom\Tools\winscp.com" ) {
|
||||
$WINSCP = "${Env:ProgramData}\Emberkom\Tools\winscp.com"
|
||||
} else { Write-Host "WinSCP does not exist!"; exit } }
|
||||
|
||||
## Prepare WinSCP script file
|
||||
$HOSTNAME = 'xfer.emberkom.net'
|
||||
$HOSTKEY = 'ecdsa-sha2-nistp256 256 5iJFeMzLK5Ld7gbLn+NlcYyI+DvbSXB8fmFJLLDh7s0='
|
||||
$USERNAME = 'JeQCXVBI80Pj3nL'
|
||||
#$PASSWORD = ''
|
||||
$SCRIPT_FILE = [System.IO.Path]::GetTempFileName()
|
||||
$UPLOAD_SCRIPT = @(
|
||||
"echo off",
|
||||
"option batch on",
|
||||
"option confirm off",
|
||||
"open sftp://${USERNAME}:${Password}@${HOSTNAME}/ -hostkey=`"${HOSTKEY}`"",
|
||||
"mkdir `"${Env:ComputerName}`"",
|
||||
"cd `"${Env:ComputerName}`"",
|
||||
"mkdir `"${Env:Username}`"",
|
||||
"cd `"${Env:Username}`"",
|
||||
"mkdir `"Manual Upload`"",
|
||||
"cd `"Manual Upload`"",
|
||||
"put -resume -nopermissions -preservetime -speed=${SpeedLimit} -resumesupport=on -neweronly `"${Path}`"",
|
||||
"exit")
|
||||
try { ForEach ($line in $UPLOAD_SCRIPT) { $line | Out-File "${SCRIPT_FILE}" -Append } }
|
||||
catch { Write-Host "Script file could not be created: ${SCRIPT_FILE}"; exit }
|
||||
|
||||
## Upload the data
|
||||
try { Start-Process -WindowStyle Hidden "${WINSCP}" -ArgumentList "/script=`"${SCRIPT_FILE}`"" -Wait }
|
||||
catch { Write-Host "Data transfer failed!" }
|
||||
|
||||
## Delete the script file
|
||||
try { Remove-Item -Path "${SCRIPT_FILE}" -Force }
|
||||
catch { Write-Host "Script file could not be deleted: ${SCRIPT_FILE}" }
|
||||
Reference in New Issue
Block a user