When working with SSH and SFTP, you may have noticed a curious difference in how ports are specified:

SSH uses the lowercase -p option, while SFTP uses the uppercase -P.


Although it might seem inconsistent, this design choice has practical reasons rooted in how these tools are built and their respective option sets.


SSH Command

The ssh command specifies the port to connect to with the lowercase -p option:

ssh -p 2222 user@hostname


The ssh utility was designed with a Unix-style command-line convention where lowercase letters are typically used for frequently used options.



SFTP Command

The sftp command specifies the port to connect to with the uppercase -P option:

sftp -P 2222 user@hostname


The sftp command is a separate utility built on top of SSH and follows slightly different conventions.

In the case of sftp, the lowercase -p is already used for a different option: preserving file attributes like times, access times and modes during file transfers.

sftp -p user@hostname


To avoid conflicts, the uppercase -P was chosen for specifying the port.

These design choices are purely based on avoiding conflicts and adhering to Unix-like conventions for command-line tools.



Links

OpenSSH Manual Pages
https://man.openbsd.org/ssh

sftp(1) — Linux manual page
https://man7.org/linux/man-pages/man1/sftp.1.html