main
Bryan Cerrati 2024-10-25 08:58:19 -04:00
commit 637e3697ca
2 changed files with 34 additions and 0 deletions

BIN
bin/pscp.exe Normal file

Binary file not shown.

34
cckdownload.ps1 Normal file
View File

@ -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