39

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?

4
  • 1
    Try escaping the "commercial at" like so sftp -oPort:8777 user\@[email protected] Commented Oct 21, 2013 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? Commented Oct 21, 2013 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. Commented Oct 21, 2013 at 16:51
  • @Tim ... escaping it is not helping. Commented Oct 21, 2013 at 16:52

3 Answers 3

55

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.

7
  • This username has not ssh access, just sftp. Commented Oct 21, 2013 at 16:48
  • @DigitalRobot s/ssh/sftp/ Commented Oct 21, 2013 at 16:54
  • @DigitalRobot This works for both ssh and sftp (and scp too). Commented Oct 21, 2013 at 16:59
  • Go on. What should we do if the passwd also contain '@' or '/' Commented Feb 9, 2017 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. Commented Feb 9, 2017 at 10:27
6
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.

2
  • The quotes do not change anything since the characters between them are not special to the shell. The sftp command receives the same arguments as in the question, and the question states that this doesn't work. Commented Mar 5, 2024 at 9:58
  • That's no different to the original suggestion in the question. All you've done is provide a pair of quotes that the shell strips before passing the string on to the sftp command Commented Mar 5, 2024 at 9:58
0

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

sftp -oPort=8777 [email protected] 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.