Topic "Best Approach For Getting Error Information Back From WinSCP"

Author Message
gjsheridan
[View user's profile]

Joined: 2014-04-24
Posts: 2
Location: New York, NY
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 diredctory, 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
Advertisements
JimBobDelicate

Guest


You can call Winscp in log mode with the batch you can also enable logging in the Winscp gui.

"C:\Program Files (x86)\WinSCP\WinSCP.exe" /console /log="Z:whereveryouputyourlog\!S!M!D!Y!T.log" /Script=Yourscript.txt

The !S - logs session name, MDYT are month, day, year, time.
Guest




JimBobDelicate wrote:
You can call Winscp in log mode with the batch you can also enable logging in the Winscp gui.

"C:\Program Files (x86)\WinSCP\WinSCP.exe" /console /log="Z:whereveryouputyourlog\!S!M!D!Y!T.log" /Script=Yourscript.txt

The !S - logs session name, MDYT are month, day, year, time.


Thanks JimBob. Will it create a log whether there's an error or not? Do you know if it's possible to only create a log if there's an error. That would allow me to look for an error log file, and if I find one, email myself. If there's no error log file, I'll know everything is OK.

Thanks,
gjsheridan
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24995
Location: Prague, Czechia
The only reliable way to check for any error is to test WinSCP exit code.

See
https://winscp.net/eng/docs/faq_script_result
https://winscp.net/eng/docs/guide_automation#results

Also make sure your script starts with option batch abort:
https://winscp.net/eng/docs/scriptcommand_option
gjsheridan
[View user's profile]

Joined: 2014-04-24
Posts: 2
Location: New York, NY
prikryl wrote:
The only reliable way to check for any error is to test WinSCP exit code.

See
https://winscp.net/eng/docs/faq_script_result
https://winscp.net/eng/docs/guide_automation#results

Also make sure your script starts with option batch abort:
https://winscp.net/eng/docs/scriptcommand_option



Thanks very much for the response prikryl. I got this working.
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