Skip to content

SFTP Non-Default Port

SFTP Default Port 22

Generally, you can sftp from client to the server through its 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.

SFTP Non-Default Port

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 sftp is smart.

Leave a Reply

Your email address will not be published. Required fields are marked *