Tuesday, March 26, 2013

scp files with spaces in the filename

scp is a great tool. Built to run over ssh it maintains a good unix design. It does however cause a few problems with it's nonchalant handling of file names.

For example, transferring a file which has a space in the name causes problems because of the amount of escaping required to get the space to persist on the remote side of the connection.

Copying files from local to remote is easy enough, just quote or escape the file name using your shell.
scp Test\ File remote:
scp 'Test File' remote:
scp "Test File" remote:

Copying files from remote to local can be more tricky
scp remtote:Test\ File .
scp: Test: No such file or directory
scp: File: No such file or directory


scp stimulus:"Test File" .
scp: Test: No such file or directory
scp: File: No such file or directory


scp "stimulus:Test File" .
scp: Test: No such file or directory
scp: File: No such file or directory


The escaping is working on your local machine but the remote is still splitting the name at the space.

To solve that, we need an extra level of escape, one for the remote server. Remember that your shell will eat the \ so you need a double \\ to send it to the remote
scp remote:Test\\\ File .
Test File              100%    0     0.0KB/s   00:00

You can also combine the remote escape with local quoting
scp remote:"Test\ File" .
or
scp "remote:Test\ File" .

Best solution of all, avoid spaces in file names. If you can't avoid it, I find the easiest solution is to replace ' ' with '\\\ '.
 

13 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. I hope there will be more of this type of publication.Tessa

    ReplyDelete
  4. The article you have shared here very awesome. I really like and appreciated your work. I read deeply your article, the points you have mentioned in this article are useful minecraft

    ReplyDelete
  5. I saw the some reference online but I don't understand perfectly, can any one help on this?

    most fun games 69

    ReplyDelete
  6. I was very pleased to find this web-site. I wanted to thanks for your time for this wonderful read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you blog post.

    Habotao.com
    Information
    Click Here
    Visit Web

    ReplyDelete
  7. The next time I read a blog, I hope that it doesnt disappoint me as much as this one. I mean, I know it was my choice to read, but I actually thought you have something interesting to say. All I hear is a bunch of whining about something that you could fix if you werent too busy looking for attention.

    Player.me
    Information
    Click Here
    Visit Web

    ReplyDelete
  8. I find this post so interesting. Keep us updated! Click here

    ReplyDelete
  9. beth dutton hat season 4 serves as a visual representation of her unwavering loyalty to her family and their ranching legacy. With its rich earthy tones and rugged texture, it embodies her deep connection to the land and the untamed nature of the American West.

    ReplyDelete
  10. "The cakespricing.com on this website are a testament to the skill and passion of the bakers."

    ReplyDelete
  11. To copy files from a local system to a remote system using Infinite Craft SCP when the filenames contain spaces, you need to properly escape the spaces.

    ReplyDelete