Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

Re: Best Approach For Getting Error Information Back From WinSCP

@retlacs: If you have problems, please post what did you try and how did it fail.
retlacs

Re: Best Approach For Getting Error Information Back From WinSCP

@gjsheridan: Can you post the sample script... Somehow I cannot get it to work...
Thank you.
gjsheridan

Re: Best Approach For Getting Error Information Back From WinSCP

Thanks very much for the response prikryl. I got this working.
gjsheridan

Best approach for getting error information back from WinSCP

Hello, I'm new here. I have a batch file for ftp'ing files using WinSCP. It currently works, but has no error handling in it at all.

We had a situation recently where the FTP session timed out for some reason, and we didn't know until days later.

I'll post all the relevant code if that will help, but I guess I should first explain what I'm trying to do.

The following command is in the original batch file:
D:\winscp520\winscp.com /script=D:\psft\ChaseDev\ftp_chase_ach_eft_dev.txt > D:\psft\ChaseDev\ftp_chase_output.txt

The script file ftp_chase_ach_eft_dev.txt just changes to a specific local directory and does a put of two different file name patterns. Normally there is only one file in the source directory, so it is normally just uploading one file.

The output of the command above is redirected to the file ftp_chase_output.txt.

Someone was working on this before me and started to add some error handling.

What they're doing is reading the contents of the file ftp_chase_output.txt after the command above runs, and looking for the word "Authenticated" and for the words "Error code".

This might catch some errors, but I'm worried that there will be things that we'll miss. Is there any way to tell WinSCP to create a log file with a certain name if anything goes wrong, including a problem with authentication, or a timeout? And to not create any log file at all if everything succeeds? I'm not going to attempt to deal with any errors. I just want to send an email to myself if anything at all goes wrong.

The code is already written in a batch file, so I guess I'll save some time by leaving it that way, but if I can get better error handling by using another language, I'm comfortable doing that. I know C# and I've done a little bit of PowerShell programming. I know Java too, but I haven't seen that mentioned. Does WinSCP work with both Java and C#, or just C#. Just curious.

It would be nice to have lots of flexibility in error handling, but most likely I'll just add this check for any error (if that's possible) and never touch this code again. So if it's possible to do it correctly with a batch file, I guess that would be my preference. One other consideration is emailing. If that's easier from C# than from a batch file, for example, then I would lean toward C#.

If anyone has any advice on this, it would be greatly appreciated.

Thanks,
gjsheridan