4

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?

  • 1
    Take a look at this link. stackoverflow.com/questions/9425222/… It looks like you should be able to replace the spaces with underscores. Have you tried that already? – Andrew May 19 '16 at 23:27
  • Yup, I did try to use underscores instead of spaces (and no quotes), and although it doesn't raise an error I guess it treats it as a different user because when I use the correct password, it fails with "Permission Denied". – cavpollo May 19 '16 at 23:36
6

You could use ~/.ssh/config. It's the per-user configuration file for SSH (and commands based on SSH like scp and sftp). Create it, if it does not exist, and add:

Host 192.168.0.42
    User "User Name Spaces"

For example:

Host localhost
    User "foo bar"

Then:

$ scp test.txt  localhost:
foo bar@localhost's password: 

(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:

Host foo
    Hostname 192.168.0.42
    User "User Name Spaces"

Then you can conveniently do:

ssh foo
scp file foo:

And avoid having to type the whole IP address.


An alternative, if you have tar available on both ends:

tar c myfile.txt | ssh "User Name Spaces"@192.168.0.42 tar x

tar creates a tar archive, saved to standard output and piped through to SSH, where it becomes the input to tar x, which extracts the archive. You can use options like -C to change the directory (or do so as a shell command before tar: ssh … 'cd foo; tar x). You could also use compression and save a bit on network bandwitdh:

tar zc myfile.txt | ssh "User Name Spaces"@192.168.0.42 tar zx
  • I didn't understand exactly how tar and the pipe character work together with ssh, but it sounds like a good idea. Sadly, while testing it, it says something along the lines of "tar isnt recognized as an internal or external command" [Note: tar does work on my side, Ubuntu. I guess it comes from the Windows PC not knowing what to do with the command.] – cavpollo May 19 '16 at 23:45
  • Hmm. I assumed you might have installed those utilities along with SSH. No hope of installing tar on the Windows system (you can get it from MSYS2 or Cygwin)? – muru May 19 '16 at 23:48
  • No, unfortunetly the windows pc is out of my control =\ (The ssh server is running thanks "Bitvise SSH Server") – cavpollo May 19 '16 at 23:53
  • @cavpollo try the update – muru May 20 '16 at 0:04
  • 1
    @cavpollo Yes, it's the same way. I hadn't noticed the comment. OSX uses OpenSSH, the same implementation Ubuntu uses, so it's applicable here too. – muru May 20 '16 at 0:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.