VB.NET: How to interpret Upload Results

Advertisement

ianbhenderson73
Joined:
Posts:
4
Location:
Glasgow, Scotland

VB.NET: How to interpret Upload Results

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

Reply with quote

Advertisement

as1981
Joined:
Posts:
19

Hello,

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

Thanks

Andrew

Reply with quote

kamii47
Joined:
Posts:
4

Re: IsSuccess

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

Reply with quote

Advertisement

ianbhenderson73
Joined:
Posts:
4
Location:
Glasgow, Scotland

Re: IsSuccess

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.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,442
Location:
Prague, Czechia

Re: IsSuccess

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:
https://winscp.net/eng/docs/library_wildcard

Reply with quote

as1981
Joined:
Posts:
19

Re: VB.NET: How to interpret Upload Results

martin 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

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,442
Location:
Prague, Czechia

Re: VB.NET: How to interpret Upload Results

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.

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.

Reply with quote

Advertisement

You can post new topics in this forum