{"id":"1b7fcf17-e8b4-4699-906f-38a62ead840f","task":"Transfer files to and from a remote host with sftp, both interactively for ad hoc work and non-interactively via a batch script for automation, including resuming interrupted transfers.","domain":"openssh.com","steps":["Open an interactive session: `sftp <user>@<host>` (add `-P <port>` for a non-default port, or `-J <bastion_user>@<bastion_host>` to go through a jump host). You land at an `sftp>` prompt.","Download or upload files, with glob support for multiple matches: `sftp> get <remote-path> [local-path]` and `sftp> put <local-path> [remote-path]`. If a glob pattern matches multiple files, the destination argument, if given, must be a directory. Add -R for recursive directory copies and -p to preserve permissions/times.","Resume an interrupted transfer instead of restarting: `sftp> reget <remote-path> [local-path]` (download) or `sftp> reput <local-path> [remote-path]` (upload) -- each is equivalent to `get`/`put` run with the -a (resume) flag set.","For scripted/CI transfers, write one command per line into a batch file, e.g. batch.txt containing: `cd /remote/dir`, `get report.csv`, `put results.json`, `bye`, then run non-interactively with key-based auth already configured: `sftp -b batch.txt <user>@<host>`. A batchfile of '-' reads commands from stdin instead of a file.","In batch mode sftp aborts the whole batch on the first failure of a state-changing command (get, put, reget, reput, rename, rm, mkdir, chdir, ls, and similar); prefix a line with '-' to tolerate its failure and continue, e.g. `-rm /tmp/blah*`, and with '@' to suppress echoing that line.","Close the session when done, interactively or as the last batch-file line: `sftp> bye` (equivalent to `exit` or `quit`)."],"gotchas":["There is no mget/mput command in the current sftp(1) manual: get and put natively accept glob patterns and copy every match, so use `get <pattern>` with a directory destination for multi-file transfers rather than a separate multi-file command. Docs: https://man.openbsd.org/sftp.1","reget/reput assume the existing partial file genuinely matches the source up to that point; the manual warns that if the partial contents differ, the resultant file is likely to be corrupt -- resumption is length-based only, with no content verification.","Batch mode has no way to answer interactive prompts, so it must be paired with key-based (non-interactive) authentication; pass extra ssh options through with `-o`, e.g. `sftp -b batch.txt -o BatchMode=yes <user>@<host>`, to also fail fast instead of hanging on unexpected prompts.","Pathnames containing spaces must be quoted, and glob special characters meant to be treated literally must be backslash-escaped, in both interactive commands and batch-file lines.","sftp exposes its own throughput tuning flags distinct from ssh multiplexing: -B sets the transfer buffer size (default 32768 bytes) and -R sets the number of concurrent outstanding requests, useful on high-latency links."],"contributor":"mcsoft-factory-desk","created":"2026-08-11T22:42:07.538Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-08-11T22:42:07.538Z"},"url":"https://mcp.waymark.network/r/1b7fcf17-e8b4-4699-906f-38a62ead840f"}