What is SFTP?
SFTP is a way to upload, download and manage files on a server over an encrypted SSH connection. It runs inside the same kind of session you use for a terminal login, normally on port 22, so your password or key, your commands and the file contents are all encrypted. If you can log in to a server with SSH, you can almost always use SFTP with the same username and key.
SCP is an older, simpler tool for one-line copies over SSH, while SFTP gives you an interactive session in which you can list, rename, delete and change permissions. This guide covers both, plus rsync and GUI clients.
Quick checklist
- Confirm SSH access and note the host, username and SSH port.
- Set up an SSH key rather than relying on a password.
- For an interactive session, run
sftp user@hostand useputandgetto move files. - For a one-off copy, run
scp file user@host:/path/; add-rfor folders and-Pfor a custom port. - For large or repeated syncs, use
rsyncover SSH. - After uploading, check ownership and permissions with
ls -l.
What does SFTP stand for?
SFTP stands for SSH File Transfer Protocol. It was designed as a subsystem of SSH version 2, and the OpenSSH sftp client and sftp-server are what most Linux servers use. So what is SFTP not? It is not FTP: it shares no commands or ports with FTP and needs no FTP server.
The protocol that really is FTP with encryption added is FTPS, which wraps FTP in TLS. FTPS uses the FTP ports and an FTP server, while SFTP needs only SSH.
SFTP vs FTP vs FTPS
| Protocol | Runs over | Usual port | Encrypted | Login |
|---|---|---|---|---|
| FTP | Plain TCP | 21 plus data ports | No | FTP account password |
| FTPS | FTP with TLS | 21 (explicit) or 990 (implicit) | Yes, when TLS is on | FTP account password |
| SFTP | SSH | 22, or the server's SSH port | Always | SSH user, with a key or password |
In any SFTP vs FTP comparison, the deciding point is that plain FTP sends your password and files unencrypted, so anyone on the network path can read them. Use SFTP wherever SSH is available. On cPanel servers, note that the separate FTP accounts you create in cPanel cannot log in by SFTP; SFTP uses the cPanel account's own username. The cPanel port numbers guide lists which ports each service needs.
How to use SFTP from the command line
The sftp client ships with OpenSSH on Linux and macOS, and with the OpenSSH client on Windows 10 and 11. Connect like this:
sftp deploy@203.0.113.10
sftp -P 2222 deploy@203.0.113.10
The second line uses a custom SSH port; note the capital -P. At the sftp> prompt, commands that act on the server have plain names, and their local equivalents start with l:
pwd,ls,cd: show, list and change the remote folder.lpwd,lls,lcd: the same on your own computer.put file.zip: upload a file to the current remote folder.get backup.sql: download a file to the current local folder.put -R siteandget -R logs: copy whole folders.mkdir,rename,rm,chmod 644 index.php: manage remote files.exitorbye: close the session.
A typical upload session looks like this:
sftp> lcd ~/projects/site
sftp> cd public_html
sftp> put -R assets
sftp> ls -l
sftp> exit
For scripts, put the commands in a file and run sftp -b commands.txt deploy@203.0.113.10. Batch mode needs key login, because it cannot stop to ask for a password.
GUI clients: FileZilla, WinSCP and Cyberduck
If you prefer drag and drop, the common desktop clients all speak SFTP:
- FileZilla (Windows, macOS, Linux): in Site Manager choose SFTP - SSH File Transfer Protocol, enter the host and port, and set the logon type to Key file to point at your private key. Do not pick "FTP over TLS", which is FTPS.
- WinSCP (Windows): choose SFTP as the file protocol. It can also use keys loaded in PuTTY's Pageant.
- Cyberduck (macOS and Windows): pick SFTP in the connection dialog and select your private key.
In every client, the host, port, username and key are the ones you use for ssh.
How to use SCP
The scp command copies files in a single step, with a syntax modelled on cp. A remote path is written as user@host:path. Here is how to scp in the common cases:
# upload a file
scp site.zip deploy@203.0.113.10:/home/deploy/
# download a file into the current folder
scp deploy@203.0.113.10:/var/log/nginx/error.log .
# copy a folder recursively
scp -r assets deploy@203.0.113.10:/var/www/site/
# custom port, specific key, keep times and modes
scp -P 2222 -i ~/.ssh/id_ed25519 -p backup.tar.gz deploy@203.0.113.10:/home/deploy/
scp command options worth knowing
-rcopies directories recursively.-P portsets the SSH port. It is a capital letter because lowercase-ppreserves modification times, access times and file modes.sshitself uses lowercase-pfor the port, which catches many people out.-i keyfilechooses the private key.-Oforces the legacy SCP protocol, for servers without SFTP.
Since OpenSSH 9.0, scp uses SFTP underneath
OpenSSH 9.0, released in April 2022, made SFTP the default transport for scp, replacing the legacy scp/rcp protocol. The command line is unchanged, but there are two practical effects. First, you no longer need to add extra quotes around spaces or wildcards in remote filenames, and doing so can now make the copy fail. Second, the server needs its SFTP subsystem enabled. Remote paths that start with ~ depend on the server's sftp-server supporting path expansion, which OpenSSH added in 8.7, so on older servers use a full path such as /home/deploy/. If you meet an old server that only speaks legacy SCP, add -O.
rsync over SSH for large or repeated transfers
rsync sends only the parts of files that changed, which makes it far quicker than SFTP or SCP for redeploying a site or refreshing a backup copy. It uses SSH as its transport:
rsync -avz --dry-run site/ deploy@203.0.113.10:/var/www/site/
rsync -avzP -e 'ssh -p 2222' site/ deploy@203.0.113.10:/var/www/site/
-a recurses and keeps permissions and timestamps, -z compresses, and -P shows progress and keeps partly sent files so a rerun can resume. The trailing slash on site/ copies the folder's contents rather than the folder itself. Run with --dry-run first, especially before adding --delete. rsync must be installed on both ends.
Use SSH keys instead of passwords
SFTP, SCP and rsync all authenticate exactly as ssh does, so one key covers all of them. Create a key once on your computer and add the public half to the server:
ssh-keygen -t ed25519
ssh-copy-id deploy@203.0.113.10
ssh-copy-id is not included with the Windows OpenSSH client; on Windows, paste the contents of your .pub file as a new line in ~/.ssh/authorized_keys on the server instead. Never share the private key, the file without .pub.
On cPanel you can generate or import keys under Security, SSH Access, then authorise the public key there. With a key in place you can turn off password login on a VPS, and scripted transfers no longer need a stored password.
Port 22 or a custom port
SFTP has no port of its own: it listens wherever sshd does, which is port 22 unless the administrator changed it. If SSH runs on another port, every tool needs telling: sftp -P, scp -P, ssh -p, rsync -e 'ssh -p N' and the port field in your GUI client. To avoid typing it each time, add a Host block with a Port line to ~/.ssh/config; the OpenSSH tools all read it. If a connection is refused or times out, work through SSH connection refused: causes and fixes.
Permissions and ownership after upload
Files arrive owned by the user you logged in as. On a cPanel account that is your account user, which is what you want. On a VPS, files uploaded as deploy may not be readable or writable by the web server user, so fix ownership with chown or put both users in a shared group. Typical web permissions are 644 for files and 755 for folders:
find /var/www/site -type d -exec chmod 755 {} +
find /var/www/site -type f -exec chmod 644 {} +
Double-check the path first, and re-add execute permission to any scripts afterwards.
Never use 777 to make an error go away; it lets any process on the server change your files. A 403 error straight after an upload is often a permissions problem, covered in the 403 Forbidden guide.
SFTP and SCP on Bigdomainhost
On Web & cPanel hosting, SSH access is available on request, so ask support to switch it on before you use SFTP or SCP. Until then, cPanel's File Manager handles uploads in the browser. When SSH is on, log in with your cPanel username, not an FTP account.
A Linux KVM VPS includes SSH with full root access, in Mumbai (BOM-1) or Delhi NCR (DEL-1). If you paste your SSH public key at order time, password login is disabled from the first boot, so SFTP and SCP work with that key straight away. The panel's per-instance firewall denies inbound traffic except SSH on port 22, so if you move SSH to a custom port, open that port in the panel firewall first. The VPS quickstart covers keys and first login. For help, call +91 75994 50220 during IST hours, WhatsApp the same number at any time, or email support@bigdomainhost.com.
Sources (checked )
- OpenBSD manual pages: sftp(1)
- OpenBSD manual pages: scp(1)
- OpenSSH: OpenSSH 9.0 release notes
- cPanel documentation: How to configure your SFTP client
- WinSCP documentation: Transfer protocols
- Linux man-pages (man7.org): rsync(1) manual page