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

pizzaazzip

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"
jsb2210

Syntax for filenames with spaces

Hello -

I am having a heck of a time getting the right syntax for winscp when there are spaces in the file names. Works great with no spaces.
I tried replacing the backticks with double quotes, so it is double double quotes. Do I need the back ticks and double double quotes?
$winscp = "C:\Program Files (x86)\WinSCP\winscp.com"
$ftpsite = "sftp://sitename:22 -privatekey=D:\Serverkey\key.ppk"
$ftpdirectory = "/remotefolder"
$outfile = "d:\winscp.out"
$filepath = "D:\path\name name.gpg"
 
[string] $cmdline1 = "& `"$winscp`" /command `"option batch abort`" `"option confirm off`" "
$cmdline1 += " `"open $ftpsite`" `"cd $ftpdirectory`" `"put $filepath`" `"exit`" > $outfile"
 
Invoke-Expression $cmdline1