Get successful upload response even when transfer is unsuccessful

Advertisement

hitmand
Joined:
Posts:
2
Location:
Brighton

Get successful upload response even when transfer is unsuccessful

Hi

I have a script that uploads to an SFTP server. The server it is uploading to is filename driven, meaning that if it receives a file that is an incorrect filename to what it is expecting it automatically rejects it. For some reason winscp is reporting success even if the transfer was in fact unsuccessful due to me purposely sending a file with the wrong filename, so when I log into the SFTP server as expected the file is not there. Does anyone have any idea what the issue could be?

Please see code:

try
{
write-host "Trying"
# Connect
$session.Open($sessionOptions)
write-host "connected"

# Upload files
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
$transferResult = $session.PutFiles($FullPath, "/inbox/", $False, $transferOptions)
write-host "pushed files"

# Throw on any error
$transferResult.Check()
write-host "error check"

# Print results
foreach ($transfer in $transferResult.Transfers)
{
# Success or error?
if ($transfer.Error -eq $Null)
{
$errortest = $transfer | out-string
$errortest2 = $transferResult | out-string
$errortest3 = $transferResult.Transfers | out-string

Write-Host $errortest
Write-Host $errortest2
Write-Host $errortest3

Write-Host ("Upload of {0} succeeded" -f $transfer.FileName)
Move-Item $FullPath $MovedFolder -force

}
else
{
Write-Host ("Upload of {0} failed: {1}" -f
$transfer.FileName, $transfer.Error.Message)
}
}
}
finally
{
# Disconnect, clean up
$session.Dispose()
write-host "session disposed"
stop-transcript
}

exit 0

}
catch [Exception]
{
write-host "In the catch"
Write-Host ("Error: {0}" -f $_.Exception.Message)
stop-transcript
exit 1
}

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,518
Location:
Prague, Czechia

Re: Get successful upload response even when transfer is unsuccessful

Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

Reply with quote

Advertisement

You can post new topics in this forum