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 '\\\ '.
 

18 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. What an interesting post to read. I learned new information from your article, you are doing a great job.
    Keep it Up!

    Certificationdeal

    ReplyDelete
  7. What an interesting post to read
    thanks and Keep up the good work.

    Best homeopathic doctor in Pakistan

    ReplyDelete
  8. ندرك جيدًا ان نقل العفش يعتبر من أهم الأمور التي يجب التركيز عليها؛ لهذا السبب فإنه يجب أن يتم التأكد من سلامته عند النقل فتقدم لكم شركتنا خدمات نقل العفش باحترافية بدون خدش
    شركة نقل عفش بالرياض
    ان الحمام يتكاثر وجوده في فصل الشتاء و في فصل الصيف مما يجعلنا في حاجة إلى مكافحتة لذلك يتم تركيب طارد حمام مع افضل شركات تنظيف مخلفات الحمام والطيور وتركيب أفضل أنواع شبك طوارد الحمام
    شركة مكافحة الحمام بالرياض
    تمثل المكيفات دور هام في حياتنا في اشهر الصيف
    شركة خبراء الرياض تقدم خدمات تركيب المكيفات بالادوات الخاصة للمكيف مع ارخص الاسعار وعمالة مدربة ومتخصصون في هذا المجال
    شركة تركيب مكيفات بالرياض

    ReplyDelete
  9. 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
  10. 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
  11. Amazing post, thanks for sharing this article. Really Enjoyed Alot Thanks for Sharing
    Reading Taxi Service

    ReplyDelete
  12. Your Blog is very informative .wish to see much more like this. Thanks for sharing.
    Crown Taxi Tunbridge Wells

    ReplyDelete
  13. Really nice and helpful Article. Thanks For Sharing
    Metro Taxi Tunbridge Wells

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

    ReplyDelete