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

suppose the user is "user@example.com" and the ftp server is just "example.com"

I will end with

sftp -oPort:8777 user@example.com@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?

  • 1
    Try escaping the "commercial at" like so sftp -oPort:8777 user\@domain.com@domain.com – 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. – SpaceDog Oct 21 '13 at 16:51
  • @Tim ... escaping it is not helping. – SpaceDog Oct 21 '13 at 16:52

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 User=user@example.com 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.

|improve this answer|||||
  • This username has not ssh access, just sftp. – SpaceDog Oct 21 '13 at 16:48
  • @DigitalRobot s/ssh/sftp/ – ladaghini Oct 21 '13 at 16:54
  • @DigitalRobot This works for both ssh and sftp (and scp too). – Gilles 'SO- stop being evil' Oct 21 '13 at 16:59
  • Go on. What should we do if the passwd also contain '@' or '/' – Shicheng Guo Feb 9 '17 at 2:11
  • @ShichengGuo ??? There's no problem with @ or / in the password. You just type them. SSH doesn't even allow any way to pass the password on the command line option or in a configuration file. – Gilles 'SO- stop being evil' Feb 9 '17 at 10:27
sftp -o Port:8777 'user@domain.com'@domain.com

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

|improve this answer|||||

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

sftp -oPort:8777 user+example.com@example.com
|improve this answer|||||

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.