Skip to content

How to SFTP to a Non-Default Port in Console

  • by
Generally, you can sftp to the server by the default port 22, but sometimes, system administrators only allow privileged users to use it, you might be assigned to connect to a different port.

Try the following syntax.
[root@localhost ~]# sftp user@ftp.example.com:229
Connecting to ftp.example.com...
ssh: connect to host ftp.example.com port 22: Connection timed out
Couldn't read packet: Connection reset by peer

Sftp did not alert any syntax error, but it still connect to port 22.

After checking the manual of sftp, I got the answer in the manual:
[root@localhost ~]# man sftp
...
For example, to specify an alternate port use: sftp -oPort=24.
...

OK, let's try it.
[root@localhost ~]# sftp user@ftp.example.com -oPort=229
Connecting to ftp.example.com...
ssh: connect to host ftp.example.com port 22: Connection timed out
Couldn't read packet: Connection reset by peer

Not working, but how about switching places of the two arguments.
[root@localhost ~]# sftp -oPort=229 user@ftp.example.com
Connecting to ftp.example.com...
The authenticity of host ...
RSA key fingerprint is ...
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ...
user@ftp.example.com's password:
sftp> pwd
Remote working directory: /home/user

Now, it's working. But I don't think the utility "sftp" is smart.

Leave a Reply

Your email address will not be published.