Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

hitmand

Hi

The issue has somehow resolved itself. Thank-you for your help anyway.

Regards,
martin

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.
hitmand

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
}