Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

ThomasHeaton

Keeping a connection open while running PowerShell commands

Hi all,

I'm creating automation where we download files from an SFTP, do various PowerShell commands on the data retrieved, wait 3 minutes and do the same thing again.

However, I want to be able to keep the connection to the server open indefinitely while I then query the SFTP every 3 minutes.

I want to achieve this by using a do/while loop in PowerShell that executes every 3 minutes.

I do not want to keep creating a connection/logging into the SFTP we have as I feel our firewall may pick this up as potentially unwanted behaviour.

My basic idea is
## Keep connection open [TESTING]
& "C:\Program Files (x86)\WinSCP\WinSCP.com" `
  /log="FILEPATH" /ini=nul `
  /command `
    "open sftp://Name[IP]/ -hostkey=`"`"[Key]`"`" -privatekey=`"`"C:\TEST`"`"" `
    "cd /Outbound" `
 
# Keep getting files every 3 minutes
DO WHILE
[ GET DATA ]
[ DO SOMETHING WITH DATA ]
 
FINALLY
"exit"


Apologies if this isn't clear enough

Is this possible?