$linuxjunkies
>

sftp(1)

Interactive secure file transfer program using SSH.

UbuntuDebianFedoraArch

Synopsis

sftp [OPTION]... [USER@]HOST[:PATH]

Description

sftp is an interactive file transfer program, similar to ftp, which performs all operations over an encrypted SSH transport. It connects and logs in to the specified HOST, optionally at a specific remote directory. Once connected, the user is presented with an sftp> prompt where commands can be entered to navigate, list, and transfer files.

sftp is more secure than traditional ftp since all traffic, including passwords, is encrypted. It uses the same authentication methods as ssh (public key, password) and can reuse existing ssh configurations.

Common options

FlagWhat it does
-P portSpecify the port to connect to on the remote host (default: 22)
-CEnable compression of data in transit
-o optionPass ssh options to the underlying ssh connection (e.g., -o StrictHostKeyChecking=no)
-b batchfileRead commands from a batch file instead of stdin; useful for automation
-vIncrease verbosity for debugging connection and protocol issues
-i identity_fileSpecify private key file for authentication
-4Force IPv4 connections only
-6Force IPv6 connections only

Examples

Connect to example.com as 'user' and enter interactive sftp shell

sftp [email protected]

Connect to a non-standard SSH port (2222)

sftp -P 2222 [email protected]

Execute sftp commands from a batch file without interactive prompt

sftp -b commands.txt [email protected]

Use a specific private key file for authentication

sftp -i ~/.ssh/id_ed25519 [email protected]

Connect and automatically change to remote directory /home/user/files

sftp [email protected]:/home/user/files

Connect with compression enabled for slower connections

sftp -C [email protected]

Related commands