Kaur
Kaur

Reputation: 501

WinSCP session not ending with CLOSE command

I am currently writing a script that calls WinSCP, connects an SFTP session, transfers a group of files from a local server to a remote server, closes the connection, then exits. I see multiple WinSCP.exe processes that left running after every run. What is wrong with my syntax?

"C:\Program Files (x86)\WinSCP\WinSCP.com" /log="C:\imports\WinSCP.log" /ini=nul /command "open sftp://[email protected]/writable/ -hostkey=""ssh-......"" -privatekey=""C:\mykeys\UN_private.ppk"""  "put -latest C:\import\customers\*.csv /imports/*.csv" "close" "exit"

Upvotes: 0

Views: 1458

Answers (2)

Kaur
Kaur

Reputation: 501

My code used ^ to separate the commands in separate lines. Removed "close" ^ from the code. Moved "exit" next to last command. For some reason it didn't like that I formatted the batch file with ^.

Here is the old code

"put -latest C:\import\customers\*.csv /imports/*.csv" ^
"close" ^
 "exit"

and the working code -

"put -latest C:\import\customers\*.csv /imports/*.csv" "exit"

Upvotes: 0

Martin Prikryl
Martin Prikryl

Reputation: 202494

Single run of WinSCP.com only ever runs a single instance of WinSCP.exe, never more.

WinSCP.com also runs in the same Windows job as WinSCP.exe. So if WinsCP.com terminates, Windows makes sure that WinSCP.exe is terminated too, no matter how wrong you write your script or what bug can be in WinSCP itself preventing an explicit WinSCP.exe termination.

So it's quite likely that there's something else, that causes the WinSCP.exe processes be left behind, not your script. Or your description of the problem is not accurate.

Upvotes: 0

Related Questions