Topic "Get successful upload response even when transfer is unsuccessful"

Author Message
hitmand
[View user's profile]

Joined: 2016-05-24
Posts: 2
Location: Brighton
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
}
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24552
Location: Prague, Czechia
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
[View user's profile]

Joined: 2016-05-24
Posts: 2
Location: Brighton
Hi

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

Regards,
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License