Topic "Error handling in a batch file"

Author Message
Mark_D
[View user's profile]

Joined: 2016-10-27
Posts: 4
Location: London, England
Firstly, thanks for any help offered in advance. I do not use batch files a great deal and therefore my knowledge is limited.

I have created a batch file to connect to a number of ftp servers and copy a directory which works fine if the server is online. Occasionally the server may be offline and as such the batch file stops at that point and closes.

What I would like to happen is if an error occurs with one line it moves to the next.

In my code below I have each connection command and get commands in one line for each server.

If one line causes any errors I want to move to the next until all lines are complete. The actual batch file has about 50 such lines.

Code:
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
   /log="C:\Users\??????????\Documents\Backup Test\WinSCP.log" /ini=nul ^
   /command ^
    "lcd ""C:\Users\??????????\Documents\Backup Test""" ^
    "open ftp://tridium:??????????@10.203.61.100/" "cd /ffs0/niagara/stations" "get "KPMG_15CSQ_L13_DVD_N"" ^
    "open ftp://tridium:??????????@10.203.61.103/" "cd /ffs0/niagara/stations" "get "L13_15CSQ_S"" ^
    "exit"


I have googled error handling in batch files but do not know enough to decide if the error handling is a command line event or a WinSCP event hance me posting here first.

Any help much appreciated.
martin◆
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26730
Location: Prague, Czechia
In this case, the easiest solution is to execute new WinSCP instance for each session:

Code:
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
   /log="C:\Users\??????????\Documents\Backup Test\WinSCP.100.log" /ini=nul ^
   /command ^
    "lcd ""C:\Users\??????????\Documents\Backup Test""" ^
    "open ftp://tridium:??????????@10.203.61.100/" "cd /ffs0/niagara/stations" "get "KPMG_15CSQ_L13_DVD_N"" ^
    "exit"

"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
   /log="C:\Users\??????????\Documents\Backup Test\WinSCP.103.log" /ini=nul ^
   /command ^
    "lcd ""C:\Users\??????????\Documents\Backup Test""" ^
    "open ftp://tridium:??????????@10.203.61.103/" "cd /ffs0/niagara/stations" "get "L13_15CSQ_S"" ^
    "exit"
Advertisements

You can post new topics in this forum

Search

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