Error in script - could not be renamed to target file name
"PS C:\XXX\test> .\script.ps1
Upload of C:XXX\test\test1.xml failed: Transfer was successfully finished, but temporary transfer file
'test1.xml.filepart' could not be renamed to target file name 'test1.xml'. If the problem persists, you may try to turn
off transfer resume support."
How do I turn this off and send files as they are instead of changing them in temp?
Can you tell me what do I add to this script below and were exactly do I add it to make this script working without any errors.
Moving local files to different location after successful upload
param (
$localPath = "C:\upload\*",
$remotePath = "/home/user/",
$backupPath = "C:\backup\"
)
try
{
# Load WinSCP .NET assembly
Add-Type -Path "WinSCPnet.dll"
# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
$sessionOptions.HostName = "example.com"
$sessionOptions.UserName = "user"
$sessionOptions.Password = "mypassword"
$sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
$session = New-Object WinSCP.Session
try
{
# Connect
$session.Open($sessionOptions)
# 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, moving to backup" -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
}
thanks
Dragan