SFTP
What SFTP is, how it differs from FTP, FTPS and SCP, and what the host must allow.
SFTP is the SSH File Transfer Protocol. It runs as a subsystem inside an SSH connection, so it uses the same login, the same keys and the same encryption as SSH.
Not the same as
- FTP. An older protocol that sends passwords in clear text and uses extra connections.
- FTPS. FTP over TLS. Different protocol, different port, different server.
- SCP. An older SSH copy tool. Modern OpenSSH runs it over SFTP. It has no directory listing.
SFTP has nothing to do with FTP apart from the name.
What the host needs
- SSH access for the account.
- The
sshd_configlineSubsystem sftp ...(usually/usr/lib/openssh/sftp-serverorinternal-sftp). Without it the host closes the session. - Permission on the folders. SFTP follows the file system permissions of the account.
Some hosts limit a user to one folder (a chroot, ChrootDirectory) with internal-sftp. Paths inside it start at /. If the login closes at once and the server log says "bad ownership or modes for chroot directory", see SFTP chroot: bad ownership or modes for chroot directory. If the account's login shell is nologin, an external SFTP server is blocked too and SSH prints This account is currently not available.; internal-sftp can still work. See SSH "This account is currently not available" (nologin shell).
Common commands (command line client)
ls, cd, pwd list and change folders
get file download
put file upload
mkdir, rm, rmdir create and delete
rename old new
chmod 640 file change permissions
To copy a whole folder, see sftp put -r: copy a whole folder, and "Couldn't canonicalize".
What a good client does
- Shows folders, sizes and dates, and lets you upload, download, rename and delete.
- Resumes an interrupted transfer when the server supports it.
- Keeps the transfer running while the app is in the background, if the platform allows it.
Common problems
- "Subsystem request failed". The host does not allow SFTP for this user, or
sshd_confighas no sftp subsystem. Since OpenSSH 9.0,scpfails the same way; see scp "subsystem request failed on channel 0" and "scp: Connection closed". - "Permission denied". The account cannot read or write that path. For root-owned files, see SFTP with sudo: edit root-owned files with sftp -s.
- A shell that prints text at login. Output from
.bashrccan break SFTP. Move it to interactive shells only. - Host key warning. See Known hosts.
Related
- How SSH works
- IND$FILE
- SFTP "Received message too long"
- App guide: SFTP
- SSH "This account is currently not available" (nologin shell)
- sftp put -r: copy a whole folder, and "Couldn't canonicalize"
- SFTP with sudo: edit root-owned files with sftp -s
- Do scp and sftp use ~/.ssh/config? Host aliases, -F and -P
- SFTP chroot: bad ownership or modes for chroot directory
- SFTP and scp to z/OS: EBCDIC text conversion and data sets
- EZA2537E and 451: z/OS FTP records longer than the LRECL
- scp "subsystem request failed on channel 0" and "scp: Connection closed"