Linux – How to copy file with spaces remotely using sftp

filenameslinuxremotesftpwindows 7

I am trying to copy a file from windows 7 to linux debian using SFTP
Filename is ba ck.bak

I am using SFTP to remotely put file through windows command prompt
If filename is back.bak then command executes successfully

sftp> sftpc root@xxx.xxx.xxx.xxx:xx -pw=XXXXX -cmd="put back.bak /tmp"

but if filename is ba ck.bak, i.e. with spaces error occurs
I had tried using

-cmd="put 'ba ck.bak' /tmp"

but doesn't work

I am using this file in a windows batch file, so I cannot execute by logging into sftp session and executing command there. I can also execute these commands through shell file, but I would not want to create new file each time.

Best Answer

Okay, I got the answer on my own. Instead of searching all over the internet, I checked the help for the command, and got the answer in the examples:

sftpc root@xxx.xxx.xxx.xxx:xx -pw=XXXXX -cmd="put \"ba ck.bak\" /tmp"

Had to escape the qoutes.

Related Question