How to track when a file is fail to transfer?

Advertisement

huahsin68
Joined:
Posts:
2

How to track when a file is fail to transfer?

According to the sample code in C# from this link > https://winscp.net/eng/docs/library#csharp, there is a piece that tracking whether the file is successfully transfer. As shown here:

// 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?

Reply with quote

Advertisement

huahsin68
Joined:
Posts:
2

Can I perform the check using the following 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?

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
28,802
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

Reply with quote

Advertisement

You can post new topics in this forum