RE: how to copy filename with spaces using scp
From: Spiewak, Jakub (jakub.spiewak_at_citigroup.com)
Date: Tue, 16 Dec 2003 07:33:34 -0000 To: "John Davidorff Pell" <firstname.lastname@example.org>, "Jerry Geis" <email@example.com>
If I may have a question
If You are trying to interact with Server placed on Windows platform, You face problems with not only files with space but also with areas with space.
if I would like to transfer c:\Program Files\test\test file.tmp
to my Unix box, what shall I do?
From: John Davidorff Pell [mailto:firstname.lastname@example.org]
Sent: Monday, December 15, 2003 2:05 AM
To: Jerry Geis
Cc: Secure Shell
Subject: Re: how to copy filename with spaces using scp
Jerry Geis <email@example.com> wrote:
> How do I escape the spaces in an automated way?
> I am not typing this command it is running from an
> automated file. something like
> ssh remote find /home/jerry > file_list
> the use every file name in the file_list and scp
> that file from remote to local.
> John Davidorff Pell wrote:
> You should try:
> $ scp remote:"/file\ with\ spaces.txt" /tmp
> instead of
>> scp "remote:/file with spaces.txt" /tmp
$ scp remote:"\"file with spaces.txt\"" /tmp
This may not work because what local scp thinks the file name is:
\"file with spaces.txt\" includes the quotes, which it shouldn't. You
could use "--unsafe" to get around that, but here is a better way:
$ scp remote:"\"file with spaces.txt\"" "/tmp/file with spaces.txt"
That shouldn't be too hard to do inside the script. :-)
It seems, from your example, that you are trying to copy *many* files.
This is NOT the best way to go about if for a number of reasons:
A) It is slow.
B) It has tremendous overhead
C) It floods the logs
D) It is slow.
E) It takes a very long time.
F) Are you seeing a pattern?
Here is a better way to copy large amounts of files:
$ cd /tmp
$ ssh remote tar c /home/jerry | tar x
Basically, what this will do is archive your entire home folder, send
it, then unarchive it. Here is a version with compression:
$ cd /tmp
$ ssh remote "tar c /home/jerry | gzip" | gunzip | tar x
For *best* compression (over a slow link), change gzip to gzip -9
You will end up with a folder named home in /tmp that contains a folder
named jerry that has your entire home folder contents in it... :-D
If you do not want the extra folders (/tmp/home/jerry) then you can use
the -C flag for tar, but i'll leave that to you. (hint: "man tar")
I've CC'd the list again, in case anyone else has any tips. :-)
-- ". . . Through the cold and darkness we will look back on this day and fall into oblivion. Through a brilliance beyond twilight we will rise again, ready to face the dangers that befall on us . . ."