Topic "How to track when a file is fail to transfer?"

Author Message
huahsin68
[View user's profile]

Joined: 2014-08-20
Posts: 2
According to the sample code in C# from this link > http://winscp.net/eng/docs/library#csharp, there is a piece that tracking whether the file is successfully transfer. As shown here:

Code:
// Print results
foreach (TransferEventArgs transfer in transferResult.Transfers)
{
    Console.WriteLine("Upload of {0} succeeded", transfer.FileName);
}


I did some experiment on this code, I found out that this code unable to track when the file was fail to transfer. May I know how could I track when a file is failed to transfer?
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
No. The code that checks if there is any failure is transferResult.Check();. Alternatively check TransferOperationResult.Failures.

See http://winscp.net/eng/docs/library_session#results
_________________
Martin Prikryl
huahsin68
[View user's profile]

Joined: 2014-08-20
Posts: 2
Can I perform the check using the following code?

Code:
TransferOperationResult tor = session.PutFiles(...);
tor.Check();

if( tor.Transfers.Count > 0 )
{
   // suscess
}
else
{
   // fail
}


I just test on the code and it works. But I wasn't sure whether this is the right way of checking?
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
If there's a failure, the tor.Check() throws. So should actually never get to the // fail branch (unless you selected no files for transfer, but than it's not a failure). On the other hand the tor.Transfers.Count > 0 is not an indication of success, but possibly of a partial success only. But again, mere fact that tor.Check() did not throw is an indication of success.
_________________
Martin Prikryl
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