iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
To copy an entire directory tree from a remote server to your machine, open an SFTP session and run get -R with the remote directory path. The uppercase -R flag makes the retrieval recursive. The command is documented in the current OpenBSD sftp(1) manual, which lists the syntax as get [-afpR] remote-path [local-path].
Run the recursive download
- Start the session. For example,
sftp alice@example.com. If the server listens on a non-default port, put-P portbefore the destination, such assftp -P 2222 alice@example.com. The uppercase-Pselects the connection port. - At the
sftp>prompt, check where you are on both sides. Runpwdto see the remote working directory andlpwdto see the local one. Using fully qualified paths removes most ambiguity. - Run the transfer:
get -R /remote/path/to/directory ./local-destination. Choose a local destination that your local account can write to and that has room for the whole tree. - If you need the original permissions and access times on the copied files, add the lowercase
-pflag:get -pR /remote/path/to/directory ./local-destination.
How the local path behaves
The local path is optional. If you leave it out, the retrieved directory is saved under the same name as the remote path. If the remote path matches more than one file, for example when it contains a wildcard, the local path you give must be an existing directory. Giving a single target name in that case will not work.
Options that change the result
Three options decide what the copy looks like. They do different jobs, so you choose among them rather than treating them as interchangeable.
| Option | Works with | What it does | When to use it | Caveat from the manual |
|---|---|---|---|---|
-R |
get |
Retrieves a directory and its contents recursively | Any time you want a directory tree, not a single file | Symbolic links are not followed |
-p |
get |
Preserves file permissions and access times | When the local copy must match the remote file attributes | Only changes what is copied; it does not affect which files are included |
-a, or the separate reget command |
get, reget |
Attempts to resume a partial transfer | After an interrupted download where the local partial file is known to match the remote file | If the contents differ, the manual warns that the result is likely corrupt |
The reget command is documented as equivalent to get with -a. It also accepts -R, so you can resume a recursive transfer with reget -R.
Limits that can leave a copy incomplete
A recursive download can finish without errors and still be missing content. Check these before you rely on the copy.
- Symbolic links are skipped. Recursive transfers do not follow symlinks. If a file or subdirectory is reachable only through a symlink, it will not be in your local copy.
- Resumption assumes a match. The
-aoption andregetassume the local partial copy matches the remote file. If the local file was changed, came from a different source, or differs from the remote version, the resumed file is likely corrupt. In that case, delete the local partial file and download it again. - Metadata is not guaranteed without
-p. Without-p, the copied files are not documented to keep the remote permissions and access times.
What the client cannot confirm
The OpenSSH client manual describes the command, but it cannot tell you whether a given server offers SFTP or whether your account can read the directory. Those depend on the server’s configuration, your authentication method, and the file permissions on the remote side. If the transfer fails before any files arrive, check your login and read access on the server, and confirm with the server administrator that SFTP is enabled for your account. Behavior can also vary by service, so a command that works on one host may behave differently on another.
Rank #2
The examples above use placeholder names such as alice@example.com and /remote/path/to/directory. Replace them with your own host, user, and paths.
Free tools Windows power users keep installed
One-click scans. No signup required.
Quick Recap
Best Value
- Wireless File Transfer
- Full functional SSH Server
- SFTP File Transfer
- Protect USB charging port
- Multiple users with multiple paths
Rank #4
- Wireless File Transfer
- Full functional SSH Server
- SFTP File Transfer
- Protect USB charging port
- Multiple users with multiple paths
Rank #3
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.

