Another method to do this
I know this is an old thread but I use a somewhat antiquated scripting system and I figured I would share how I got this to work for me. I'm sure someone in the future will roast me but this gets the job done for what I needed. I just realized I've only done this for default port numbers so perhaps I can just add
:271
or whatever the port number happens to be at the end of the server address. Whenever I have to call a PowerShell command in a cmd command prompt I just write everything with single quotes ('
) instead of double-quotes ("
) but I couldn't get this to work with the singles hence all the backslash (\
) escape characters. Note the difference between the backtick (`
) vs single quote ('
), I learned that was required for this task, my previous version which didn't allow spaces was wwaaaayyyyy more simple and didn't require any use of PowerShell (although I couldn't get reporting to work without it). If you have a space in your output file (I use that to email me the result, handy if I typo'd something) you might need to escape that entire folder path (although you might be able to get away with single quotes like Out-File -Encoding ASCII 'C:\Win SCP\WinSCPResult.txt'"
and yes that "
is required).
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -command "C:\WinSCP\winscp.com /command \"open SFTP://YourUsername:YourPassword@Your.Server.net\" \"get `\"`\"/Some Folder/File On Server WithOrWithoutSpaces.zip`\"`\" `\"`\"C:\WinSCP\Output File.zip`\"`\"\" \"exit\" | Out-File -Encoding ASCII C:\WinSCP\WinSCPResult.txt"