Retries and timeout option for WinSCP command-line batchfile

Advertisement

Teqleez
Joined:
Posts:
4

Retries and timeout option for WinSCP command-line batchfile

Hi all,

In a batch file, I have the following command that sometimes fails, and retries again and again. I wish to ensure that I can control the number of retries and the pause between them, so that I avoid being blocked from the server:

wscp418.exe /console /passive /command "option batch on" "option confirm off" "open ftp://username:pw@ftp.someserver.com" "cd somefolder" "mkdir %CurDate%" "cd %CurDate%" "put C:\somefolder\todaysbackups\*.zip" "close" "exit"
How can I specify the number of retries if the connection fails, and the time between them?
Would be practical to know both if it is possible to specify retries etc. on the command line, but also how to make a "ini-file" or "config-file" and point to it form the command line.

Apart from the number of retries, here are the options I need:

Pause: Does some command option like this exist? I am in need of a way to specify the number of seconds between EACH retry. (Example: 5 retries, with a pause of 300 seconds between each one if no connection is made)

Timeout: the number of seconds to wait for a connection. Does such an option exist?

I imagine something like this in myinifile.ini :
retries = 5
pause = 300
timeout = 30

I also assume that I can let the myinifile.ini be in the same folder as the executable, and call it from the above mentioned command line like this
"/ini=myinifile.ini"

How exactly should such statements be put in an ini file? One on each line?
Is it important if there are spaces or not around the = (equal) characters?

Reply with quote

Advertisement

Teqleez
Joined:
Posts:
4

Documentation reference (may need a batch-file workaround)

PS. I know about this one:
https://winscp.net/eng/docs/scriptcommand_option

If there are no options like the ones I need, is there a practical way around it?

I guess the batch file can be hand-coded to handle it.
If so, I would appreciate if anyone could point me to an example batch file for such logic.

Reply with quote

Teqleez
Joined:
Posts:
4

Re: Retries and timeout option for WinSCP command-line batchfile

martin wrote:

Thanks for your post. This issue is being tracked already.
I do not know of any workaround.

Thanks Martin.
Would be nice if a link to this thread could be added to the comments on that tracker as a FYI to the people working on it. I dont have a login there.

Reply with quote

Teqleez
Joined:
Posts:
4

Workaround: using some batch tricks

Is there any way at all to control/limit how many times a winscp console session tries to reconnect?

If it was possible to force it to try only once or x times, then I want to make a batch file workaround that should be generally useful in handling such situations. Anyone want to join in creating one? Anyone that has some example code that could be used as a starting point?

I remember using a windows tool called "sleep.exe" in some batch files to set timeout before the batch continued. That was on Windows XP, I think. If I remember correctly, that command-line tool is freely available from the Microsoft web site.

some commands
sleep 5 (seconds)
more commands

Brainstorm/example:
The logic chould be something like this:
Notice: This is UNFINISHED and quite messy, with broken logic... See step 3 (UPLOAD3/RETRY3), this is just a quick braindump, step 3 is closer to what 1 and 2 should be (all steps should hav same logic)

0. PS. The following will not make sense or be possible if it is not possible to force winscp to stop reconnecting...

1. how to trap if a connection fails? Need to be able to identify a failed connection attempt from within the batch file for this to work. Possible?

:UPLOAD1
:RETRY1
if retry="" set retry=0
if retry=1 goto UPLOAD1
if retry=11 set retry=111
if retry=111 goto UPLOAD1
if retry=1111 goto UPLOAD2 (skip, go to next)

2. UPLOAD1: connect and put file (group) 1 
(probably have to do chuncks of files with several winscp console commands in order to be able to deal with the timeout logic from the batch file)

3. sleep N seconds
4. On error goto RETRY
5. goto UPLOAD2

:UPLOAD2
if retry="" goto UPLOAD2B
if retry=1 goto UPLOAD1
:RETRY2
if retry=2 goto UPLOAD2A
if retry=22 set retry=222
if retry=222 goto UPLOAD2B
if retry=2222 goto UPLOAD3 (skip, go to next file upload)

:UPLOAD2B

6. UPLOAD2 connect and put file (group) 2
7. sleep N seconds
8. On error goto RETRY
9. goto UPLOAD3



:UPLOAD3
:RETRY3

if retry=3 goto NEXT3
if retry=33 goto NEXT33
if retry=333 goto NEXT333
if retry=3333 goto UPLOAD4 (skip to next file upload)

:NEXT3
if retry=3 set retry=33
goto UPLOAD3B

:NEXT33
if retry=33 set retry=333
goto UPLOAD3B

:NEXT333
if retry=333 set retry=3333
goto UPLOAD3B

:NEXT3333
if retry=3333 set retry=0
goto UPLOAD4

:UPLOAD3B
10. UPLOAD3 connect and put file (group) 3
11. sleep N seconds
12. On error goto RETRY
13. goto UPLOAD4 (etc...)

:UPLOAD4

14. UPLOAD3 connect and put file (group) 4
15. sleep N seconds
16. On error goto RETRY
17. goto DONE

REM (etc...)

:RETRY
if retry=1 goto RETRY1
if retry=11 goto RETRY11
if retry=111 goto RETRY111
if retry=1111 goto RETRY1111

if retry=2 goto RETRY2
if retry=22 goto RETRY22
if retry=222 goto RETRY222
if retry=2222 goto RETRY2222

if retry=3 goto RETRY3
if retry=33 goto RETRY33
if retry=333 goto RETRY333
if retry=3333 goto RETRY3333

if retry=4 set retry=44
if retry=44 goto RETRY44
if retry=444 goto RETRY444
if retry=4444 goto RETRY4444
(should go out of the loop here)

if retry=5 goto RETRY5
if retry=6 goto RETRY6
if retry=7 goto RETRY7
if retry=8 goto RETRY8
if retry=2 goto RETRY9
REM (etc...)

:DONE
9. exit

Reply with quote

Advertisement

Christianca
Guest

Is it common winscp console to stay unavailable after yum...

Is it common winscp console to stay unavailable after yum install? If i click on the screen after that I will receive that answer from windows whether I want or not close the program....

Reply with quote

martin
Site Admin
martin avatar

Re: Is it common winscp console to stay unavailable after yum...

Christianca wrote:

Is it common winscp console to stay unavailable after yum install? If i click on the screen after that I will receive that answer from windows whether I want or not close the program....
No. Can you post a screenshot?

Reply with quote

Advertisement

You can post new topics in this forum