PowerShell: No way to disable reconnect

Advertisement

BeFrank
Joined:
Posts:
1

PowerShell: No way to disable reconnect

Hello,

there are a lot of postings here about how to avoid automatic reconnect. Some of the postings say, one has to user the option "reconnect". But as you can see in documentation, in PowerShell it's only possible to set a TimeSpan and it is not possible to set the option to off, like in batch mode. I tried many ways to get it somehow to work, but it did not (even tried AdditionalExecutableArguments, which always should be null). Here is my testcase using SFTP to a Ubuntu Server that I'm able to control:
The script first opens the connection and than waits for user input. I can see on the server auth.log the process id under which the connection is opened. Than, on server side, I kill all processes of the user (sudo killall -u <username goes here>)
I then go back to the script and do the input, so it continues. I can see, that it is doing a reconnect.
$session.Open($sessionOptions)
Read-Host "Script waiting. Press enter to go on"
$transferResult = $session.PutFiles($localPath, $remotePath, $false, $transferOptions)
So how to switch off reconnects using PowerShell?

Regards
Frank

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
36,051
Location:
Prague, Czechia

Re: Powershell: No way to disable reconnect

Setting the reconnecttime to off actually enables infinite reconnects:
https://winscp.net/eng/docs/scriptcommand_option#reconnecttime
Quite the opposite of what you want. You want to set the option to a low value (like one second). Though there's currently no way to turn it off completely (neither in scripting, nor in .NET assembly). If your server is still running, WinSCP will likely manage to reconnect even with the one second limit.

I've added a request for this to the tracker:
https://winscp.net/tracker/1981
You can vote for it there.

Reply with quote

Advertisement

You can post new topics in this forum