Checking WinSCP connection status in PowerShell script

1

1

I have a script that get files from one location to another. My script works fine.

However I'd like to check first for "connected sessions". With SSH.NET PowerShell module I checked this with:

$ASESSION = (Get-SshSession -ComputerName $AHOST).connected

Is there a way of doing this with WinSCP?

MuH

Posted 2014-11-24T20:46:26.430

Reputation: 11

I'm confused. Are you already using SSH.NET library in PowerShell? Get-SshSession is a hint for this. And now you want to use PowerShell together with WinSCP?

– nixda – 2014-11-24T21:22:40.887

That is correct. In former days we had two unix systems and used SSH.NET library in our script. Now we changed to Windows and want to change to WinSCP.NET assembly. – MuH – 2014-11-25T17:50:43.100

Sorry, this may sound like a stupid question from me. But you are aware that SSH.NET can be used in PowerShell, right? This said, you can use your old script with PowerShell under Windows. Or am I missing something? – nixda – 2014-11-25T19:42:11.930

Answers

0

If I understand correctly, you want to check if connection is still alive before each transfer, right?

While WinSCP .NET assembly has the $session.Opened property, its value actually does not change in real-time. It changes only, when some method of the Session class is called.

Anyway, what's the point? Just try to transfer files and see, if it succeeds or not. Testing connection beforehand does not guarantee you that the transfer succeeds.

Martin Prikryl

Posted 2014-11-24T20:46:26.430

Reputation: 13 764

Thank you for your answer. I change my script to transfer files without previously connection check. – MuH – 2014-11-25T17:40:38.987