How to copy file with spaces remotely using sftp

2

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.

Master Chief

Posted 2014-10-08T14:09:28.853

Reputation: 141

Answers

2

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.

Master Chief

Posted 2014-10-08T14:09:28.853

Reputation: 141

0

You must cancel out those spaces using '\'. So your command would be,

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

That will make the shell not see the space in the file name.

dtigue

Posted 2014-10-08T14:09:28.853

Reputation: 19

I am sorry, but that doesn't work as expected. Terminates with "Invalid Command Option: /tmp" – Master Chief – 2014-10-09T05:44:43.807