Attck of teh AzN Cow flu! (cowbert) wrote in unixadmin,
Attck of teh AzN Cow flu!
cowbert
unixadmin

escaping colons in filenames

I have this weird problem where no matter how I try to escape the colon in a file name, I cannot get rsync or scp to copy it, because it parses the colon and thinks that the string preceding the colon in the filename is a hostname (and complains that it cannot to remote to remote transfers, which is, uh, sort of common sense :)

So far, I've been working around this by sticking the files that have colons in them in a folder and them using -r to copy the contents of that folder, but I feel so ashamed having to resort to that (worse than the unnecessary use of cat(1)).

Edit: Here is the specific problem I am having:

% scp myfile\:foo somehost:/somedir/
error: unknown host myfile
scp "myfile:foo" somehost:/somedir/
error: unknown host myfile
% rsync "myfile:foo" somehost:/somedir/
error: cannot transfer files between remote hosts
  • Post a new comment

    Error

    default userpic

    Your IP address will be recorded 

  • 5 comments
I'm not exactly sure how you are going about it, but note that if you use the localhost and double quotes you can get around this problem[1]. You can also use a BASH for loop for this purpose[2]. In this situation using ssh keys might be best. Again, I'm just stabbing in the dark re: your actual problem. Post more info if you get the chance.

[1]

michael@bevilacqua:~/test$ rsync -avP localhost:test/"foo:foo" testd/
michael@localhost's password:
receiving file list ...
1 file to consider
foo:foo
0 100% 0.00kB/s 0:00:00 (xfer#1, to-check=0/1)

sent 42 bytes received 126 bytes 67.20 bytes/sec
total size is 0 speedup is 0.00
michael@bevilacqua:~/test$ ls -al testd/
total 8
drwxrwxr-x 2 michael staff 4096 Feb 1 18:06 .
drwxrwxr-x 3 michael staff 4096 Feb 1 18:01 ..
-rw-rw-r-- 1 michael staff 0 Feb 1 18:01 foo:foo


[2]

michael@bevilacqua:~/test$ for i in foo* ; do rsync -avP localhost:test/"$i" testd/ ; done
michael@localhost's password:
receiving file list ...
1 file to consider
foo:foo
0 100% 0.00kB/s 0:00:00 (xfer#1, to-check=0/1)

sent 42 bytes received 126 bytes 67.20 bytes/sec
total size is 0 speedup is 0.00
michael@bevilacqua:~/test$ ls testd/
foo:foo
rsync -avP localhost:test/"foo:foo" testd/

You don't need quotes here — they're parsed by the shell, and rsync doesn't even see them. What makes this work is the fact that you have a slash before the second colon.
right my problem is:

% rsync "myfile:foo" somehost:/somedir/
error: cannot transfer files between remote hosts

I think uniheliodem's putting at least the relative path marker will cause it to parse the first file locally.
If you're referring to wombat's comment, then yes, that should work.

Deleted comment

Nice!