Hi Jimmy,
I have this script working here.
I'll show you my script and maybe you can solve your problem:
*A tip: DoubleCheck your Winscp software version and Windows permissions.
My Winscp version is: 5.7.7
try
{
# Load WinSCP .NET assembly
Add-Type -Path "C:\WinSCP\WinSCPnet.dll"
# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
$sessionOptions.HostName = "*****"
$sessionOptions.UserName = "*****"
$sessionOptions.Password = "*****"
$sessionOptions.SshHostKeyFingerprint = "*****"
$session = New-Object WinSCP.Session
try
{
# Connect
$session.Open($sessionOptions)
$localPath = "******"
$remotePath = "******"
$backupPath = "******"
# Upload files, collect results
$transferResult = $session.PutFiles($localPath, $remotePath)
# Iterate over every transfer
foreach ($transfer in $transferResult.Transfers)
{
# Success or error?
if ($transfer.Error -eq $Null)
{
Write-Host ("Upload of {0} succeeded" -f
$transfer.FileName)
# Upload succeeded, move source file to backup
Move-Item $transfer.FileName $backupPath
}
else
{
Write-Host ("Upload of {0} failed: {1}" -f
$transfer.FileName, $transfer.Error.Message)
}
}
}
finally
{
# Disconnect, clean up
$session.Dispose()
}
exit 0
}
catch [Exception]
{
Write-Host $_.Exception.Message
exit 1
}