Topic "VB.NET: How to interpret Upload Results"

Author Message
ianbhenderson73
[View user's profile]

Joined: 2015-08-28
Posts: 4
Location: Glasgow, Scotland
Hi

I've been using WinSCP for years, but this is the first time I've done it using a .NET assembly.

I'm in the process of writing an application which will automatically generate a file and then transfer them to a supplier's sFTP site. I've managed to get pretty much everything written, but now I want to be able to verify that the upload was successful. Since this application is going to be running constantly and generating files as and when the need arises, it'll effectively be unattended and therefore I'd want to be able to populate information into a SQL database table which shows the success (or otherwise) of each stage in the process.

The code that I've written in VB.net creates new SessionOptions, Session, TransferOptions and TransferOperationResult objects and populates those as needed. I'd hoped there might be a member of TransferOperationResult which would tell me the success/failure status of the transfer in progress, preferably with some supporting information if the transfer failed. So far though, I've been unable to find anything.

If anyone can provide me with details of where I need to look, I'll be extremely grateful.

TIA

Is there any way of catching the status of an upload? I've tried various
Advertisements
as1981
[View user's profile]

Joined: 2015-04-18
Posts: 16
Hello,

I'm not using .net but I think you can use transferResult.IsSuccess or something similar. It returns true or false.

Thanks

Andrew
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
Correct, use TransferOperationResult.IsSuccess.

If you need the error message, see TransferOperationResult.Failures[0].Message (C# syntax) and any inner exceptions for yet more details.

See https://winscp.net/eng/docs/library_transferoperationresult
ianbhenderson73
[View user's profile]

Joined: 2015-08-28
Posts: 4
Location: Glasgow, Scotland
Hi both

Many thanks for coming back to me. I've yet to test my implementation but on the face of it, the code that you've both supplied looks as if it'll do what I need it to do.
kamii47
[View user's profile]

Joined: 2015-09-14
Posts: 4
One odd thing i have notice about this TransferOperationResult is that when i have a file name like test[46]_2.iso e.t.c though file hasn't been transfered but i still get ISSuccess = true.
I know the issue was because of special characters in the file name but this IsSuccess is not releable. you can simply list the directory where you have uploaded the file and check the existence of the filename in that list
ianbhenderson73
[View user's profile]

Joined: 2015-08-28
Posts: 4
Location: Glasgow, Scotland
kamii47 wrote:
One odd thing i have notice about this TransferOperationResult is that when i have a file name like test[46]_2.iso e.t.c though file hasn't been transfered but i still get ISSuccess = true.
I know the issue was because of special characters in the file name but this IsSuccess is not releable. you can simply list the directory where you have uploaded the file and check the existence of the filename in that list


My only concern with that approach is that the company that runs the remote server has scripts set up which detect the presence of an incoming file and transfer that file elsewhere for processing. Whilst a directory list would work in the majority of cases, there may be instances where the remote script will run in that split second between the file being placed and the directory list being completed.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
kamii47 wrote:
One odd thing i have notice about this TransferOperationResult is that when i have a file name like test[46]_2.iso e.t.c though file hasn't been transfered but i still get ISSuccess = true.
I know the issue was because of special characters in the file name but this IsSuccess is not releable. you can simply list the directory where you have uploaded the file and check the existence of the filename in that list

It is reliable. The test[46]_2.iso is a file mask. If there's no file matching the file mask (and the test[46]_2.iso file does NOT match the test[46]_2.iso mask), then WinSCP won't transfer anything. And it's not an error, hence the IsSuccess is true. If you expect something to transfer, test also TransferOperationResult.Transfers.Count > 0. Anyway, the actual solution is to pass the filename though Session.EscapeFileMask before passing it to Session.GetFiles or Session.PutFiles.

It's actually documented:
http://winscp.net/eng/docs/library_wildcard
as1981
[View user's profile]

Joined: 2015-04-18
Posts: 16
prikryl wrote:
Correct, use TransferOperationResult.IsSuccess.

If you need the error message, see TransferOperationResult.Failures[0].Message (C# syntax) and any inner exceptions for yet more details.

See https://winscp.net/eng/docs/library_transferoperationresult


Hello,

If my transfer operation is transferring more than one file could I get more than one error message? So for example could I have a message in TransferOperationResult.Failures[0].Message and TransferOperationResult.Failures[1].Message?

If that it the situation then can I get a count of the failures and loop through them? Maybe TransferOperationResult.Failures.count?

Thanks

Andrew
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
as1981 wrote:
If my transfer operation is transferring more than one file could I get more than one error message? So for example could I have a message in TransferOperationResult.Failures[0].Message and TransferOperationResult.Failures[1].Message?

Quite rarely, but it is possible.

Quote:
If that it the situation then can I get a count of the failures and loop through them? Maybe TransferOperationResult.Failures.count?

It's .Count (capital C, while that does not matter in VB.NET).
The Failures is a ICollection.
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