Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

Use sftp for encrypted file transfers over SSH. Run sftp user@host from your Linux shell to start an interactive session, then use commands such as get to download, put to upload, ls and cd for the remote server, and lls and lcd for your local computer. The 15 examples below label exactly where each command runs and explain the options that commonly cause mistakes.

These forms follow the OpenSSH client documented by the Ubuntu Noble and Debian testing manuals. Options and server extensions can vary by distribution, so check man sftp on the machine you will use.

Before you start

  • Install the OpenSSH client package (often called openssh-client).
  • Have an SSH account, hostname or IP address, and the correct authentication method.
  • Know whether a path is remote (on the server) or local (on your Linux computer).

At the normal shell prompt, commands begin with sftp. After you connect, the prompt changes to sftp>; commands entered there are SFTP commands, not ordinary shell commands.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

15 practical SFTP commands

1. Connect interactively

Run at your Linux shell:

sftp user@host

Replace user and host with your account and server. After host-key verification and authentication, you receive an sftp> prompt. Type exit or press Ctrl-D to disconnect.

2. Connect on a non-default port

Run at the shell:

sftp -P 2222 user@host

Capital -P selects the SFTP/SSH port. The default is normally 22; use the port supplied by your administrator. Do not confuse this with lower-case -p, which preserves metadata during a transfer.

3. Select an identity file

Run at the shell:

sftp -i ~/.ssh/id_ed25519 user@host

-i tells the client which private key to offer. Protect the key with suitable permissions and use its matching public key in the server account’s authorized_keys. If the key has a passphrase, SFTP may ask for it unless an SSH agent is providing it.

4. List the remote directory

Run at the sftp> prompt:

ls -lah

This lists the current remote directory, including hidden entries, in a long, human-readable format. The output is from the server, not your local filesystem.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

5. Show the remote working directory

Run at the sftp> prompt:

pwd

pwd prints the remote directory that SFTP currently treats as its working location. It is useful before a relative get or put, especially when the server starts you in a directory different from the one you expected.

6. Change the remote directory

Run at the sftp> prompt:

cd /remote/path

Use an absolute path or a path relative to the remote working directory. Confirm the result with pwd. A failed cd normally means the directory does not exist or your account lacks permission.

7. List a local directory

Run at the sftp> prompt:

lls -lah /local/path

lls runs a local listing while you remain inside SFTP. Without a path, it lists the local working directory. This is the local counterpart to remote ls.

8. Change the local directory

Run at the sftp> prompt:

lcd /local/path

lcd changes where relative local destinations are created. Check it with:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
lpwd

lpwd reports the local working directory; pwd reports the remote one.

9. Download one file

Run at the sftp> prompt:

get /remote/path/report.csv

get copies from remote to local. If you omit a local destination, SFTP uses the current local directory and the source filename. You can specify a different filename:

get /remote/path/report.csv ./latest-report.csv

10. Upload one file

Run at the sftp> prompt:

put ./report.csv /remote/path/report.csv

put copies from local to remote. Ensure the remote account can write to the destination directory. When a wildcard matches several files, the destination you provide must be a directory, for example put ./logs/*.gz /remote/path/logs/.

11. Download while preserving permissions and times

Run at the sftp> prompt:

get -p /remote/path/archive.tar

Lower-case -p preserves the file’s permissions and access times when possible. It does not preserve ownership. The corresponding upload form is put -p local-file remote-file.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

12. Download a directory recursively

Run at the sftp> prompt:

get -R /remote/path/project ./project-copy

-R traverses directories and transfers their contents. Recursive SFTP does not follow symbolic links encountered during traversal, so linked files or directories will not be copied as their targets. Use put -R for the reverse direction.

13. Resume an interrupted download

Run at the sftp> prompt:

reget /remote/path/archive.tar

reget resumes a local partial file and is equivalent to get -a. Resume only when the existing partial copy came from the same source version. If the remote file changed, the resulting file can be corrupt; delete the partial file and perform a fresh get when in doubt.

14. Resume an interrupted upload

Run at the sftp> prompt:

reput ./archive.tar /remote/path/archive.tar

reput resumes an upload and is equivalent to put -a. Verify that the remote partial file belongs to the same local source before continuing. Otherwise, remove or rename the partial remote file and upload again.

15. Run a batch file

Create commands.sftp locally:

cd /remote/incoming
put ./report.csv
get /remote/out/status.txt ./status.txt
bye

Run at the shell:

sftp -b ./commands.sftp user@host

Batch mode reads SFTP commands without interactive input. Configure key-based or another non-interactive authentication method; a password prompt cannot be answered by the batch file. A batch file can be - to read standard input. By default, an error in a specified command stops the batch. Prefix one command with a hyphen to suppress that command’s abort-on-error behavior, such as -rm /remote/old.txt.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Useful options beyond the 15 examples

Preserve metadata on uploads

Use put -p when remote permissions and access times should match the local file. Ownership is not included.

Ask for a disk flush

The -f option requests a flush after an upload. Actual remote durability depends on server support for the [email protected] extension, so do not treat it as universally available.

Copy between remote paths

Some servers provide a remote-side copy (also called cp) command through the copy-data extension. It can avoid downloading and re-uploading a file, but it is conditional on that server capability.

Inspect remote filesystem usage

The df SFTP command depends on the server’s [email protected] extension. If unsupported, use the server’s normal shell or administration tools instead.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Control bandwidth and compression

At the shell, -l limit caps transfer bandwidth in Kbit/s, while -C enables SSH compression:

sftp -C -l 8000 user@host

Compression can help text-heavy data on a constrained link and hurt already-compressed files or CPU-limited systems. The bandwidth limit is a ceiling, not a guaranteed transfer rate.

Interactive versus batch operation

Mode Best for Authentication Failure behavior
Interactive Exploring directories, checking results, and making one-off transfers Can accept prompts such as a key passphrase You decide what to run next
Batch (-b) Repeatable deployments, scheduled jobs, and predefined transfer sets Must work without interactive input Specified command errors normally stop the batch; prefix a command with - to ignore its error
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common errors and fixes

“Could not resolve hostname”

Check spelling, DNS, VPN access, and whether the host is reachable from this network. Try the server’s IP address only if your administrator supports it.

“Connection refused” or a timeout

Confirm the port with your administrator and use capital -P. A firewall, security group, VPN requirement, or stopped SSH service can cause the same symptom.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

“Permission denied” during get or put

For downloads, verify read permission on the remote file and execute permission on each parent directory. For uploads, verify write permission on the remote directory and check disk quota.

“No such file or directory”

Run pwd, lpwd, and ls/lls to determine which side has the wrong path. Remember that a path beginning with / is interpreted on the relevant filesystem, not automatically on your local machine.

A wildcard transfer fails

When multiple files match, the destination must be a directory. Create it first and include a trailing directory path, for example put ./data/*.csv /remote/data/.

A resumed file is invalid

reget and reput assume the partial file and source are identical up to the resume point. Remove the partial copy and restart if the source may have changed.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Batch mode stops unexpectedly

Run the same commands interactively to find the failing line, verify key-based authentication, and prefix an intentionally optional command with -. Keep logs from the surrounding scheduler because SFTP itself may only report the immediate command error.

Or skip the browser setup

If your workflow also needs clean screenshots of transfer dashboards, documentation, or monitoring pages, ScreenshotNeo provides a one-call website screenshot API. It accepts consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing result. Its MCP server includes take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients.

cURL:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Python:

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

See the ScreenshotNeo documentation for the 63 capture options, including full-page and PDF capture, selectors, device presets, custom CSS and JavaScript, waiting rules, request blocking, cookies, headers, geolocation, caching, signed links, webhooks, bulk capture, and the usage API. The Free plan includes 1,000 screenshots each month with no card; paid plans start at $5 for 3,000 screenshots. Create a free ScreenshotNeo account.

Frequently Asked Questions

Can I use SFTP without opening a shell on the server?

Yes. SFTP provides file-transfer operations over SSH; you need an SSH service and account, but not necessarily shell access to perform permitted transfers.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How do I leave an SFTP session safely?

Enter bye, exit, or quit at the sftp> prompt, or press Ctrl-D.

Why are my local and remote directories different?

SFTP maintains separate working directories. Use pwd/cd for the server and lpwd/lcd for your computer.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.