]> git.ipfire.org Git - thirdparty/openssh-portable.git/blob - sftp.1
upstream: Factor out PuTTY setup.
[thirdparty/openssh-portable.git] / sftp.1
1 .\" $OpenBSD: sftp.1,v 1.143 2022/12/16 03:40:03 djm Exp $
2 .\"
3 .\" Copyright (c) 2001 Damien Miller. All rights reserved.
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
13 .\"
14 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 .\"
25 .Dd $Mdocdate: December 16 2022 $
26 .Dt SFTP 1
27 .Os
28 .Sh NAME
29 .Nm sftp
30 .Nd OpenSSH secure file transfer
31 .Sh SYNOPSIS
32 .Nm sftp
33 .Op Fl 46AaCfNpqrv
34 .Op Fl B Ar buffer_size
35 .Op Fl b Ar batchfile
36 .Op Fl c Ar cipher
37 .Op Fl D Ar sftp_server_command
38 .Op Fl F Ar ssh_config
39 .Op Fl i Ar identity_file
40 .Op Fl J Ar destination
41 .Op Fl l Ar limit
42 .Op Fl o Ar ssh_option
43 .Op Fl P Ar port
44 .Op Fl R Ar num_requests
45 .Op Fl S Ar program
46 .Op Fl s Ar subsystem | sftp_server
47 .Op Fl X Ar sftp_option
48 .Ar destination
49 .Sh DESCRIPTION
50 .Nm
51 is a file transfer program, similar to
52 .Xr ftp 1 ,
53 which performs all operations over an encrypted
54 .Xr ssh 1
55 transport.
56 It may also use many features of ssh, such as public key authentication and
57 compression.
58 .Pp
59 The
60 .Ar destination
61 may be specified either as
62 .Sm off
63 .Oo user @ Oc host Op : path
64 .Sm on
65 or as a URI in the form
66 .Sm off
67 .No sftp:// Oo user @ Oc host Oo : port Oc Op / path .
68 .Sm on
69 .Pp
70 If the
71 .Ar destination
72 includes a
73 .Ar path
74 and it is not a directory,
75 .Nm
76 will retrieve files automatically if a non-interactive
77 authentication method is used; otherwise it will do so after
78 successful interactive authentication.
79 .Pp
80 If no
81 .Ar path
82 is specified, or if the
83 .Ar path
84 is a directory,
85 .Nm
86 will log in to the specified
87 .Ar host
88 and enter interactive command mode, changing to the remote directory
89 if one was specified.
90 An optional trailing slash can be used to force the
91 .Ar path
92 to be interpreted as a directory.
93 .Pp
94 Since the destination formats use colon characters to delimit host
95 names from path names or port numbers, IPv6 addresses must be
96 enclosed in square brackets to avoid ambiguity.
97 .Pp
98 The options are as follows:
99 .Bl -tag -width Ds
100 .It Fl 4
101 Forces
102 .Nm
103 to use IPv4 addresses only.
104 .It Fl 6
105 Forces
106 .Nm
107 to use IPv6 addresses only.
108 .It Fl A
109 Allows forwarding of
110 .Xr ssh-agent 1
111 to the remote system.
112 The default is not to forward an authentication agent.
113 .It Fl a
114 Attempt to continue interrupted transfers rather than overwriting
115 existing partial or complete copies of files.
116 If the partial contents differ from those being transferred,
117 then the resultant file is likely to be corrupt.
118 .It Fl B Ar buffer_size
119 Specify the size of the buffer that
120 .Nm
121 uses when transferring files.
122 Larger buffers require fewer round trips at the cost of higher
123 memory consumption.
124 The default is 32768 bytes.
125 .It Fl b Ar batchfile
126 Batch mode reads a series of commands from an input
127 .Ar batchfile
128 instead of
129 .Em stdin .
130 Since it lacks user interaction, it should be used in conjunction with
131 non-interactive authentication to obviate the need to enter a password
132 at connection time (see
133 .Xr sshd 8
134 and
135 .Xr ssh-keygen 1
136 for details).
137 .Pp
138 A
139 .Ar batchfile
140 of
141 .Sq \-
142 may be used to indicate standard input.
143 .Nm
144 will abort if any of the following
145 commands fail:
146 .Ic get , put , reget , reput , rename , ln ,
147 .Ic rm , mkdir , chdir , ls ,
148 .Ic lchdir , copy , cp , chmod , chown ,
149 .Ic chgrp , lpwd , df , symlink ,
150 and
151 .Ic lmkdir .
152 .Pp
153 Termination on error can be suppressed on a command by command basis by
154 prefixing the command with a
155 .Sq \-
156 character (for example,
157 .Ic -rm /tmp/blah* ) .
158 Echo of the command may be suppressed by prefixing the command with a
159 .Sq @
160 character.
161 These two prefixes may be combined in any order, for example
162 .Ic -@ls /bsd .
163 .It Fl C
164 Enables compression (via ssh's
165 .Fl C
166 flag).
167 .It Fl c Ar cipher
168 Selects the cipher to use for encrypting the data transfers.
169 This option is directly passed to
170 .Xr ssh 1 .
171 .It Fl D Ar sftp_server_command
172 Connect directly to a local sftp server
173 (rather than via
174 .Xr ssh 1 ) .
175 A command and arguments may be specified, for example
176 .Qq /path/sftp-server -el debug3 .
177 This option may be useful in debugging the client and server.
178 .It Fl F Ar ssh_config
179 Specifies an alternative
180 per-user configuration file for
181 .Xr ssh 1 .
182 This option is directly passed to
183 .Xr ssh 1 .
184 .It Fl f
185 Requests that files be flushed to disk immediately after transfer.
186 When uploading files, this feature is only enabled if the server
187 implements the "fsync@openssh.com" extension.
188 .It Fl i Ar identity_file
189 Selects the file from which the identity (private key) for public key
190 authentication is read.
191 This option is directly passed to
192 .Xr ssh 1 .
193 .It Fl J Ar destination
194 Connect to the target host by first making an
195 .Nm
196 connection to the jump host described by
197 .Ar destination
198 and then establishing a TCP forwarding to the ultimate destination from
199 there.
200 Multiple jump hops may be specified separated by comma characters.
201 This is a shortcut to specify a
202 .Cm ProxyJump
203 configuration directive.
204 This option is directly passed to
205 .Xr ssh 1 .
206 .It Fl l Ar limit
207 Limits the used bandwidth, specified in Kbit/s.
208 .It Fl N
209 Disables quiet mode, e.g. to override the implicit quiet mode set by the
210 .Fl b
211 flag.
212 .It Fl o Ar ssh_option
213 Can be used to pass options to
214 .Nm ssh
215 in the format used in
216 .Xr ssh_config 5 .
217 This is useful for specifying options
218 for which there is no separate
219 .Nm sftp
220 command-line flag.
221 For example, to specify an alternate port use:
222 .Ic sftp -oPort=24 .
223 For full details of the options listed below, and their possible values, see
224 .Xr ssh_config 5 .
225 .Pp
226 .Bl -tag -width Ds -offset indent -compact
227 .It AddressFamily
228 .It BatchMode
229 .It BindAddress
230 .It BindInterface
231 .It CanonicalDomains
232 .It CanonicalizeFallbackLocal
233 .It CanonicalizeHostname
234 .It CanonicalizeMaxDots
235 .It CanonicalizePermittedCNAMEs
236 .It CASignatureAlgorithms
237 .It CertificateFile
238 .It CheckHostIP
239 .It Ciphers
240 .It Compression
241 .It ConnectionAttempts
242 .It ConnectTimeout
243 .It ControlMaster
244 .It ControlPath
245 .It ControlPersist
246 .It GlobalKnownHostsFile
247 .It GSSAPIAuthentication
248 .It GSSAPIDelegateCredentials
249 .It HashKnownHosts
250 .It Host
251 .It HostbasedAcceptedAlgorithms
252 .It HostbasedAuthentication
253 .It HostKeyAlgorithms
254 .It HostKeyAlias
255 .It Hostname
256 .It IdentitiesOnly
257 .It IdentityAgent
258 .It IdentityFile
259 .It IPQoS
260 .It KbdInteractiveAuthentication
261 .It KbdInteractiveDevices
262 .It KexAlgorithms
263 .It KnownHostsCommand
264 .It LogLevel
265 .It MACs
266 .It NoHostAuthenticationForLocalhost
267 .It NumberOfPasswordPrompts
268 .It PasswordAuthentication
269 .It PKCS11Provider
270 .It Port
271 .It PreferredAuthentications
272 .It ProxyCommand
273 .It ProxyJump
274 .It PubkeyAcceptedAlgorithms
275 .It PubkeyAuthentication
276 .It RekeyLimit
277 .It RequiredRSASize
278 .It SendEnv
279 .It ServerAliveInterval
280 .It ServerAliveCountMax
281 .It SetEnv
282 .It StrictHostKeyChecking
283 .It TCPKeepAlive
284 .It UpdateHostKeys
285 .It User
286 .It UserKnownHostsFile
287 .It VerifyHostKeyDNS
288 .El
289 .It Fl P Ar port
290 Specifies the port to connect to on the remote host.
291 .It Fl p
292 Preserves modification times, access times, and modes from the
293 original files transferred.
294 .It Fl q
295 Quiet mode: disables the progress meter as well as warning and
296 diagnostic messages from
297 .Xr ssh 1 .
298 .It Fl R Ar num_requests
299 Specify how many requests may be outstanding at any one time.
300 Increasing this may slightly improve file transfer speed
301 but will increase memory usage.
302 The default is 64 outstanding requests.
303 .It Fl r
304 Recursively copy entire directories when uploading and downloading.
305 Note that
306 .Nm
307 does not follow symbolic links encountered in the tree traversal.
308 .It Fl S Ar program
309 Name of the
310 .Ar program
311 to use for the encrypted connection.
312 The program must understand
313 .Xr ssh 1
314 options.
315 .It Fl s Ar subsystem | sftp_server
316 Specifies the SSH2 subsystem or the path for an sftp server
317 on the remote host.
318 A path is useful when the remote
319 .Xr sshd 8
320 does not have an sftp subsystem configured.
321 .It Fl v
322 Raise logging level.
323 This option is also passed to ssh.
324 .It Fl X Ar sftp_option
325 Specify an option that controls aspects of SFTP protocol behaviour.
326 The valid options are:
327 .Bl -tag -width Ds
328 .It Cm nrequests Ns = Ns Ar value
329 Controls how many concurrent SFTP read or write requests may be in progress
330 at any point in time during a download or upload.
331 By default 64 requests may be active concurrently.
332 .It Cm buffer Ns = Ns Ar value
333 Controls the maximum buffer size for a single SFTP read/write operation used
334 during download or upload.
335 By default a 32KB buffer is used.
336 .El
337 .El
338 .Sh INTERACTIVE COMMANDS
339 Once in interactive mode,
340 .Nm
341 understands a set of commands similar to those of
342 .Xr ftp 1 .
343 Commands are case insensitive.
344 Pathnames that contain spaces must be enclosed in quotes.
345 Any special characters contained within pathnames that are recognized by
346 .Xr glob 3
347 must be escaped with backslashes
348 .Pq Sq \e .
349 .Bl -tag -width Ds
350 .It Ic bye
351 Quit
352 .Nm sftp .
353 .It Ic cd Op Ar path
354 Change remote directory to
355 .Ar path .
356 If
357 .Ar path
358 is not specified, then change directory to the one the session started in.
359 .It Xo Ic chgrp
360 .Op Fl h
361 .Ar grp
362 .Ar path
363 .Xc
364 Change group of file
365 .Ar path
366 to
367 .Ar grp .
368 .Ar path
369 may contain
370 .Xr glob 7
371 characters and may match multiple files.
372 .Ar grp
373 must be a numeric GID.
374 .Pp
375 If the
376 .Fl h
377 flag is specified, then symlinks will not be followed.
378 Note that this is only supported by servers that implement
379 the "lsetstat@openssh.com" extension.
380 .It Xo Ic chmod
381 .Op Fl h
382 .Ar mode
383 .Ar path
384 .Xc
385 Change permissions of file
386 .Ar path
387 to
388 .Ar mode .
389 .Ar path
390 may contain
391 .Xr glob 7
392 characters and may match multiple files.
393 .Pp
394 If the
395 .Fl h
396 flag is specified, then symlinks will not be followed.
397 Note that this is only supported by servers that implement
398 the "lsetstat@openssh.com" extension.
399 .It Xo Ic chown
400 .Op Fl h
401 .Ar own
402 .Ar path
403 .Xc
404 Change owner of file
405 .Ar path
406 to
407 .Ar own .
408 .Ar path
409 may contain
410 .Xr glob 7
411 characters and may match multiple files.
412 .Ar own
413 must be a numeric UID.
414 .Pp
415 If the
416 .Fl h
417 flag is specified, then symlinks will not be followed.
418 Note that this is only supported by servers that implement
419 the "lsetstat@openssh.com" extension.
420 .It Ic copy Ar oldpath Ar newpath
421 Copy remote file from
422 .Ar oldpath
423 to
424 .Ar newpath .
425 .Pp
426 Note that this is only supported by servers that implement the "copy-data"
427 extension.
428 .It Ic cp Ar oldpath Ar newpath
429 Alias to
430 .Ic copy
431 command.
432 .It Xo Ic df
433 .Op Fl hi
434 .Op Ar path
435 .Xc
436 Display usage information for the filesystem holding the current directory
437 (or
438 .Ar path
439 if specified).
440 If the
441 .Fl h
442 flag is specified, the capacity information will be displayed using
443 "human-readable" suffixes.
444 The
445 .Fl i
446 flag requests display of inode information in addition to capacity information.
447 This command is only supported on servers that implement the
448 .Dq statvfs@openssh.com
449 extension.
450 .It Ic exit
451 Quit
452 .Nm sftp .
453 .It Xo Ic get
454 .Op Fl afpR
455 .Ar remote-path
456 .Op Ar local-path
457 .Xc
458 Retrieve the
459 .Ar remote-path
460 and store it on the local machine.
461 If the local
462 path name is not specified, it is given the same name it has on the
463 remote machine.
464 .Ar remote-path
465 may contain
466 .Xr glob 7
467 characters and may match multiple files.
468 If it does and
469 .Ar local-path
470 is specified, then
471 .Ar local-path
472 must specify a directory.
473 .Pp
474 If the
475 .Fl a
476 flag is specified, then attempt to resume partial transfers of existing files.
477 Note that resumption assumes that any partial copy of the local file matches
478 the remote copy.
479 If the remote file contents differ from the partial local copy then the
480 resultant file is likely to be corrupt.
481 .Pp
482 If the
483 .Fl f
484 flag is specified, then
485 .Xr fsync 2
486 will be called after the file transfer has completed to flush the file
487 to disk.
488 .Pp
489 If the
490 .Fl p
491 .\" undocumented redundant alias
492 .\" or
493 .\" .Fl P
494 flag is specified, then full file permissions and access times are
495 copied too.
496 .Pp
497 If the
498 .Fl R
499 .\" undocumented redundant alias
500 .\" or
501 .\" .Fl r
502 flag is specified then directories will be copied recursively.
503 Note that
504 .Nm
505 does not follow symbolic links when performing recursive transfers.
506 .It Ic help
507 Display help text.
508 .It Ic lcd Op Ar path
509 Change local directory to
510 .Ar path .
511 If
512 .Ar path
513 is not specified, then change directory to the local user's home directory.
514 .It Ic lls Op Ar ls-options Op Ar path
515 Display local directory listing of either
516 .Ar path
517 or current directory if
518 .Ar path
519 is not specified.
520 .Ar ls-options
521 may contain any flags supported by the local system's
522 .Xr ls 1
523 command.
524 .Ar path
525 may contain
526 .Xr glob 7
527 characters and may match multiple files.
528 .It Ic lmkdir Ar path
529 Create local directory specified by
530 .Ar path .
531 .It Xo Ic ln
532 .Op Fl s
533 .Ar oldpath
534 .Ar newpath
535 .Xc
536 Create a link from
537 .Ar oldpath
538 to
539 .Ar newpath .
540 If the
541 .Fl s
542 flag is specified the created link is a symbolic link, otherwise it is
543 a hard link.
544 .It Ic lpwd
545 Print local working directory.
546 .It Xo Ic ls
547 .Op Fl 1afhlnrSt
548 .Op Ar path
549 .Xc
550 Display a remote directory listing of either
551 .Ar path
552 or the current directory if
553 .Ar path
554 is not specified.
555 .Ar path
556 may contain
557 .Xr glob 7
558 characters and may match multiple files.
559 .Pp
560 The following flags are recognized and alter the behaviour of
561 .Ic ls
562 accordingly:
563 .Bl -tag -width Ds
564 .It Fl 1
565 Produce single columnar output.
566 .It Fl a
567 List files beginning with a dot
568 .Pq Sq \&. .
569 .It Fl f
570 Do not sort the listing.
571 The default sort order is lexicographical.
572 .It Fl h
573 When used with a long format option, use unit suffixes: Byte, Kilobyte,
574 Megabyte, Gigabyte, Terabyte, Petabyte, and Exabyte in order to reduce
575 the number of digits to four or fewer using powers of 2 for sizes (K=1024,
576 M=1048576, etc.).
577 .It Fl l
578 Display additional details including permissions
579 and ownership information.
580 .It Fl n
581 Produce a long listing with user and group information presented
582 numerically.
583 .It Fl r
584 Reverse the sort order of the listing.
585 .It Fl S
586 Sort the listing by file size.
587 .It Fl t
588 Sort the listing by last modification time.
589 .El
590 .It Ic lumask Ar umask
591 Set local umask to
592 .Ar umask .
593 .It Ic mkdir Ar path
594 Create remote directory specified by
595 .Ar path .
596 .It Ic progress
597 Toggle display of progress meter.
598 .It Xo Ic put
599 .Op Fl afpR
600 .Ar local-path
601 .Op Ar remote-path
602 .Xc
603 Upload
604 .Ar local-path
605 and store it on the remote machine.
606 If the remote path name is not specified, it is given the same name it has
607 on the local machine.
608 .Ar local-path
609 may contain
610 .Xr glob 7
611 characters and may match multiple files.
612 If it does and
613 .Ar remote-path
614 is specified, then
615 .Ar remote-path
616 must specify a directory.
617 .Pp
618 If the
619 .Fl a
620 flag is specified, then attempt to resume partial
621 transfers of existing files.
622 Note that resumption assumes that any partial copy of the remote file
623 matches the local copy.
624 If the local file contents differ from the remote local copy then
625 the resultant file is likely to be corrupt.
626 .Pp
627 If the
628 .Fl f
629 flag is specified, then a request will be sent to the server to call
630 .Xr fsync 2
631 after the file has been transferred.
632 Note that this is only supported by servers that implement
633 the "fsync@openssh.com" extension.
634 .Pp
635 If the
636 .Fl p
637 .\" undocumented redundant alias
638 .\" or
639 .\" .Fl P
640 flag is specified, then full file permissions and access times are
641 copied too.
642 .Pp
643 If the
644 .Fl R
645 .\" undocumented redundant alias
646 .\" or
647 .\" .Fl r
648 flag is specified then directories will be copied recursively.
649 Note that
650 .Nm
651 does not follow symbolic links when performing recursive transfers.
652 .It Ic pwd
653 Display remote working directory.
654 .It Ic quit
655 Quit
656 .Nm sftp .
657 .It Xo Ic reget
658 .Op Fl fpR
659 .Ar remote-path
660 .Op Ar local-path
661 .Xc
662 Resume download of
663 .Ar remote-path .
664 Equivalent to
665 .Ic get
666 with the
667 .Fl a
668 flag set.
669 .It Xo Ic reput
670 .Op Fl fpR
671 .Ar local-path
672 .Op Ar remote-path
673 .Xc
674 Resume upload of
675 .Ar local-path .
676 Equivalent to
677 .Ic put
678 with the
679 .Fl a
680 flag set.
681 .It Ic rename Ar oldpath newpath
682 Rename remote file from
683 .Ar oldpath
684 to
685 .Ar newpath .
686 .It Ic rm Ar path
687 Delete remote file specified by
688 .Ar path .
689 .It Ic rmdir Ar path
690 Remove remote directory specified by
691 .Ar path .
692 .It Ic symlink Ar oldpath newpath
693 Create a symbolic link from
694 .Ar oldpath
695 to
696 .Ar newpath .
697 .It Ic version
698 Display the
699 .Nm
700 protocol version.
701 .It Ic \&! Ns Ar command
702 Execute
703 .Ar command
704 in local shell.
705 .It Ic \&!
706 Escape to local shell.
707 .It Ic \&?
708 Synonym for help.
709 .El
710 .Sh SEE ALSO
711 .Xr ftp 1 ,
712 .Xr ls 1 ,
713 .Xr scp 1 ,
714 .Xr ssh 1 ,
715 .Xr ssh-add 1 ,
716 .Xr ssh-keygen 1 ,
717 .Xr ssh_config 5 ,
718 .Xr glob 7 ,
719 .Xr sftp-server 8 ,
720 .Xr sshd 8
721 .Rs
722 .%A T. Ylonen
723 .%A S. Lehtinen
724 .%T "SSH File Transfer Protocol"
725 .%N draft-ietf-secsh-filexfer-00.txt
726 .%D January 2001
727 .%O work in progress material
728 .Re