commit 637e3697caad99affd323df529d90c1bc3f00d1a Author: Bryan Cerrati Date: Fri Oct 25 08:58:19 2024 -0400 First diff --git a/bin/pscp.exe b/bin/pscp.exe new file mode 100644 index 0000000..3c7927d Binary files /dev/null and b/bin/pscp.exe differ diff --git a/cckdownload.ps1 b/cckdownload.ps1 new file mode 100644 index 0000000..5d822d6 --- /dev/null +++ b/cckdownload.ps1 @@ -0,0 +1,34 @@ +# Define variables +$remoteServer = "10.0.1.254" +$remoteUser = "your_username" # Replace with your username on the remote server +$remotePassword = "your_password" # Replace with your password for the remote server +$remotePath = "/volume/autobackup" +$localPath = "D:/Shared/unifibackup/" +$zipFileName = "backup_$(Get-Date -Format yyyy-MM-dd).zip" +$pscpPath = "C:\path\to\pscp.exe" # Update with the correct path to pscp.exe +$localTempFolder = "$env:TEMP\autobackup" + +# Create temporary folder +if (-Not (Test-Path $localTempFolder)) { + New-Item -ItemType Directory -Path $localTempFolder | Out-Null +} + +# SCP copy the remote folder to the local temp directory using the password +$pscpCommand = "& `"$pscpPath`" -pw `"$remotePassword`" -r `"$remoteUser@$remoteServer:$remotePath/*`" `"$localTempFolder`"" +Invoke-Expression $pscpCommand + +# Check if the files were successfully copied +if (Test-Path "$localTempFolder\*") { + # Compress the files into a zip + Compress-Archive -Path "$localTempFolder\*" -DestinationPath "$localPath\$zipFileName" + + # Cleanup the temporary folder + Remove-Item -Recurse -Force $localTempFolder + + Write-Host "Backup completed and saved as $localPath\$zipFileName" +} else { + Write-Host "Failed to copy files from remote server." +} + +# Clear the password variable from memory for security +$remotePassword = $null