Can't connect with OpenSSH sftp with custom port

1

I am using Cygwin on Windows 7. I have installed OpenSSH client and i am using it connect to Ubuntu server installed on virtualbox through localhost. I am connecting through ssh with this command:

ssh -p 3022 root@127.0.0.1

But when I try to use the same command to connect through sftp I get this message:

ssh: Could not resolve hostname 3022: Name or service not known
Connection closed

The command I am using is this

sftp -p 3022 root@127.0.0.1

Any idea why I am able to connect through ssh but not through sftp?

peter7558

Posted 2015-02-09T11:34:27.827

Reputation: 253

Answers

1

Because with sftp, the -p switch has a different meaning. It means "always preserve times". It's an argument-less switch, so the following 3022 is interpreted as a standalone argument (=host name).

To set a custom port, use -P switch (capital P), supported by OpenSSH 5.4p1 and newer:

sftp -P 3022 root@127.0.0.1

With older versions of OpenSSH use:

sftp -o Port=3022 root@127.0.0.1

Beware that in some older versions of OpenSSH, the -P had yet another meaning.

Martin Prikryl

Posted 2015-02-09T11:34:27.827

Reputation: 13 764