59 lines
2.4 KiB
PowerShell
59 lines
2.4 KiB
PowerShell
param (
|
|
[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 } }
|
|
|
|
## Make sure the iTunes backup directory exists and has data
|
|
$ITUNES_SOURCE_DIR = "${Env:AppData}\Apple Computer\MobileSync\Backup\"
|
|
if ( Test-Path $ITUNES_SOURCE_DIR ) {
|
|
if ( !($(Get-ChildItem "${ITUNES_SOURCE_DIR}" | Select-Object -First 1 | Measure-Object).Count -gt 0 ) )
|
|
{ Write-Host "No iTunes backup exists!"; exit } }
|
|
else { "iTunes is not installed."; 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 = '7a2jr9Zf9uXMqbGgC2xyu4nuoaYtxg'
|
|
$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 `"iTunesBackups`"",
|
|
"cd `"iTunesBackups`"",
|
|
"put -resume -nopermissions -preservetime -speed=${SpeedLimit} -resumesupport=on -neweronly `"${ITUNES_SOURCE_DIR}*`"",
|
|
"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}" }
|