32

I have to sftp to a server to a specific port but the username contains the @ symbol.

suppose the user is "[email protected]" and the ftp server is just "example.com"

I will end with

sftp -oPort:8777 [email protected]@example.com

what will obviously not work, as I have tested.

What kind of amateur creates a username with @? Ok, my boss did.

How do I solve that?

Patrick Mevzek
  • 3,130
  • 2
  • 20
  • 30
Duck
  • 4,434
  • 19
  • 51
  • 64
  • 1
    Try escaping the "commercial at" like so `sftp -oPort:8777 user\@[email protected]` – Tim Oct 21 '13 at 16:35
  • If you remove the username portion and just leave the domain, does it prompt you for the username once you've entered the command? – ladaghini Oct 21 '13 at 16:35
  • @ladaghini - this is to be used inside a script... no prompt available. Ok, I know the implications of having username and password in a script, but this username has a limited area. It has to be sftp because this server just generates usernames for sftp. – Duck Oct 21 '13 at 16:51
  • @Tim ... escaping it is not helping. – Duck Oct 21 '13 at 16:52

3 Answers3

44

Pass the user name through the -o User option, or through the equivalent User directive in the client configuration file (~/.ssh/config).

sftp -o Port:8777 -o [email protected] example.com

This applies to ssh, scp and sshfs as well. Using the configuration file instead of -o options has the advantage of also working with tools that call ssh and don't let you easily pass command line options if at all.

Patrick Mevzek
  • 3,130
  • 2
  • 20
  • 30
Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
7
sftp -o Port:8777 '[email protected]'@domain.com

This would also work, although its really quite poor form for them to provision users with this type of name.

SFTP Special
  • 71
  • 1
  • 1
0

Replacing @ ("commercial at") with + ("plus sign)" could be acceptable on some SFTP servers:

sftp -oPort:8777 [email protected]
AntonK
  • 101
  • 1