I have created a batch file containing WinSCP commands to upload files in different folders. Now, file names and folder name contain blank spaces.

It's showing an error when I'm running the batch file with those files and folders. The upload is successful when there aren't any blank spaces.

Below is the batch command that I'm running:

cd \
cd C:\Program Files\WinSCP
winscp.com /command "option echo off" "option batch on" "option confirm off" "open sftp" "put C:\abc\EXCEL\RestaurantAutomation\RestaurantReport_2012120172514\x y Report_P10_0010050075.xls /abc/MG0047/System Generated/x y Report_P10_0010050075.xls" "exit"

The error that I'm getting is:

Cannot create remote file ' /Generated/x y Report_P10_0010050075.xls'.
The file path does not exist or is invalid.
Error Code:10
Request code:3

Wrap the name-with-space with double quote again.

winscp.com /command "option echo off" "option batch on" "option confirm off" "open sftp" "put ""C:\abc\EXCEL\RestaurantAutomation\RestaurantReport_2012120172514\x y Report_P10_0010050075.xls"" ""/abc/MG0047/System Generated/x y Report_P10_0010050075.xls""" "exit"

Update: Updated the command.

  • Tried using the above suggestion. Error coming is :Unknown command 'Generated\x y Report_P10_0010050075.xls'
    – Somalia
    Jan 25 '12 at 12:32
  • My bad. Had to add two extra quotes. Can you try now?
    – Bibhas
    Jan 25 '12 at 12:39
  • Tried using double quotes.File or folder 'C:\abc\EXCEL\RestaurantAutomation\RestaurantReport_20121201 72514\x y Report_P10_0010050075' does not exist.
    – Somalia
    Jan 30 '12 at 7:34
  • The syntax with double double-quotes is explained here: winscp.net/eng/docs/commandline#syntax Jun 13 '14 at 7:10

Try it like this.

winscp.com /command "option echo off" "option batch on" "option confirm off" "open sftp" "put C:\abc\EXCEL\RestaurantAutomation\RestaurantReport_2012120172514\""x y Report_P10_0010050075.xls"" /abc/MG0047/""System Generated""/""x y Report_P10_0010050075.xls""" "exit"
  • Could you explain what your command does? It's quite long... Feb 7 '12 at 14:53

Have you tried escaping the spaces?

/abc/MG0047/System Generated/x\ y\ Report_P10_0010050075.xls

Other possibility would be to put the folders itself within quotes, but since there allready are some it might lead to confusioun.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.