I've been playing around with SCP for a while, and I've been able to transfer files from one place to another.
It all worked nicely until I needed to copy a file from Ubuntu to a Windows user who had spaces in his username (* groan *)
While I got it working for SSH like this:
ssh "User Name Spaces"@192.168.0.42
It didn't work with SCP:
scp "myfile.txt" "User Name Spaces"@192.168.0.42:folder
As it returns:
User Name Spaces: invalid user name
I've tried all kinds of things:
scp "myfile.txt" "User Name Spaces"@192.168.0.42:folder
scp "myfile.txt" "User\ Name\ Spaces"@192.168.0.42:folder
scp "myfile.txt" "User\\ Name\\ Spaces"@192.168.0.42:folder
scp "myfile.txt" "User\\\ Name\\\ Spaces"@192.168.0.42:folder
scp "myfile.txt" "'User Name Spaces'"@192.168.0.42:folder
scp "myfile.txt" "'User\ Name\ Spaces'"@192.168.0.42:folder
scp "myfile.txt" "'User\\ Name\\ Spaces'"@192.168.0.42:folder
scp "myfile.txt" "'User\\\ Name\\\ Spaces'"@192.168.0.42:folder
scp "myfile.txt" "'User Name Spaces'@192.168.0.42":folder
And so on… but nothing seems to work
Does anyone have any ideas?
Best Answer
You could use
~/.ssh/config
. It's the per-user configuration file for SSH (and commands based on SSH likescp
andsftp
). Create it, if it does not exist, and add:For example:
Then:
(I don't actually have a user named
foo bar
, so I couldn't finish the test.)You could also create an alias in
.ssh/config
:Then you can conveniently do:
And avoid having to type the whole IP address.
An alternative, if you have
tar
available on both ends:tar
creates a tar archive, saved to standard output and piped through to SSH, where it becomes the input totar x
, which extracts the archive. You can use options like-C
to change the directory (or do so as a shell command beforetar
:ssh … 'cd foo; tar x
). You could also use compression and save a bit on network bandwitdh: