1.\" $OpenBSD: sftp.1,v 1.119 2018/07/23 19:53:55 jmc 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: July 23 2018 $ 26.Dt SFTP 1 27.Os 28.Sh NAME 29.Nm sftp 30.Nd secure file transfer program 31.Sh SYNOPSIS 32.Nm sftp 33.Op Fl 46aCfpqrv 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_path 38.Op Fl F Ar ssh_config 39.Op Fl i Ar identity_file 40.Op Fl l Ar limit 41.Op Fl o Ar ssh_option 42.Op Fl P Ar port 43.Op Fl R Ar num_requests 44.Op Fl S Ar program 45.Op Fl s Ar subsystem | sftp_server 46.Ar destination 47.Sh DESCRIPTION 48.Nm 49is a file transfer program, similar to 50.Xr ftp 1 , 51which performs all operations over an encrypted 52.Xr ssh 1 53transport. 54It may also use many features of ssh, such as public key authentication and 55compression. 56.Pp 57The 58.Ar destination 59may be specified either as 60.Sm off 61.Oo user @ Oc host Op : path 62.Sm on 63or as a URI in the form 64.Sm off 65.No sftp:// Oo user @ Oc host Oo : port Oc Op / path . 66.Sm on 67.Pp 68If the 69.Ar destination 70includes a 71.Ar path 72and it is not a directory, 73.Nm 74will retrieve files automatically if a non-interactive 75authentication method is used; otherwise it will do so after 76successful interactive authentication. 77.Pp 78If no 79.Ar path 80is specified, or if the 81.Ar path 82is a directory, 83.Nm 84will log in to the specified 85.Ar host 86and enter interactive command mode, changing to the remote directory 87if one was specified. 88An optional trailing slash can be used to force the 89.Ar path 90to be interpreted as a directory. 91.Pp 92Since the destination formats use colon characters to delimit host 93names from path names or port numbers, IPv6 addresses must be 94enclosed in square brackets to avoid ambiguity. 95.Pp 96The options are as follows: 97.Bl -tag -width Ds 98.It Fl 4 99Forces 100.Nm 101to use IPv4 addresses only. 102.It Fl 6 103Forces 104.Nm 105to use IPv6 addresses only. 106.It Fl a 107Attempt to continue interrupted transfers rather than overwriting 108existing partial or complete copies of files. 109If the partial contents differ from those being transferred, 110then the resultant file is likely to be corrupt. 111.It Fl B Ar buffer_size 112Specify the size of the buffer that 113.Nm 114uses when transferring files. 115Larger buffers require fewer round trips at the cost of higher 116memory consumption. 117The default is 32768 bytes. 118.It Fl b Ar batchfile 119Batch mode reads a series of commands from an input 120.Ar batchfile 121instead of 122.Em stdin . 123Since it lacks user interaction it should be used in conjunction with 124non-interactive authentication to obviate the need to enter a password 125at connection time (see 126.Xr sshd 8 127and 128.Xr ssh-keygen 1 129for details). 130A 131.Ar batchfile 132of 133.Sq \- 134may be used to indicate standard input. 135.Nm 136will abort if any of the following 137commands fail: 138.Ic get , put , reget , reput, rename , ln , 139.Ic rm , mkdir , chdir , ls , 140.Ic lchdir , chmod , chown , 141.Ic chgrp , lpwd , df , symlink , 142and 143.Ic lmkdir . 144Termination on error can be suppressed on a command by command basis by 145prefixing the command with a 146.Sq \- 147character (for example, 148.Ic -rm /tmp/blah* ) . 149.It Fl C 150Enables compression (via ssh's 151.Fl C 152flag). 153.It Fl c Ar cipher 154Selects the cipher to use for encrypting the data transfers. 155This option is directly passed to 156.Xr ssh 1 . 157.It Fl D Ar sftp_server_path 158Connect directly to a local sftp server 159(rather than via 160.Xr ssh 1 ) . 161This option may be useful in debugging the client and server. 162.It Fl F Ar ssh_config 163Specifies an alternative 164per-user configuration file for 165.Xr ssh 1 . 166This option is directly passed to 167.Xr ssh 1 . 168.It Fl f 169Requests that files be flushed to disk immediately after transfer. 170When uploading files, this feature is only enabled if the server 171implements the "fsync@openssh.com" extension. 172.It Fl i Ar identity_file 173Selects the file from which the identity (private key) for public key 174authentication is read. 175This option is directly passed to 176.Xr ssh 1 . 177.It Fl l Ar limit 178Limits the used bandwidth, specified in Kbit/s. 179.It Fl o Ar ssh_option 180Can be used to pass options to 181.Nm ssh 182in the format used in 183.Xr ssh_config 5 . 184This is useful for specifying options 185for which there is no separate 186.Nm sftp 187command-line flag. 188For example, to specify an alternate port use: 189.Ic sftp -oPort=24 . 190For full details of the options listed below, and their possible values, see 191.Xr ssh_config 5 . 192.Pp 193.Bl -tag -width Ds -offset indent -compact 194.It AddressFamily 195.It BatchMode 196.It BindAddress 197.It BindInterface 198.It CanonicalDomains 199.It CanonicalizeFallbackLocal 200.It CanonicalizeHostname 201.It CanonicalizeMaxDots 202.It CanonicalizePermittedCNAMEs 203.It CertificateFile 204.It ChallengeResponseAuthentication 205.It CheckHostIP 206.It Ciphers 207.It Compression 208.It ConnectionAttempts 209.It ConnectTimeout 210.It ControlMaster 211.It ControlPath 212.It ControlPersist 213.It GlobalKnownHostsFile 214.It GSSAPIAuthentication 215.It GSSAPIDelegateCredentials 216.It HashKnownHosts 217.It Host 218.It HostbasedAuthentication 219.It HostbasedKeyTypes 220.It HostKeyAlgorithms 221.It HostKeyAlias 222.It HostName 223.It IdentitiesOnly 224.It IdentityAgent 225.It IdentityFile 226.It IPQoS 227.It KbdInteractiveAuthentication 228.It KbdInteractiveDevices 229.It KexAlgorithms 230.It LogLevel 231.It MACs 232.It NoHostAuthenticationForLocalhost 233.It NumberOfPasswordPrompts 234.It PasswordAuthentication 235.It PKCS11Provider 236.It Port 237.It PreferredAuthentications 238.It ProxyCommand 239.It ProxyJump 240.It PubkeyAcceptedKeyTypes 241.It PubkeyAuthentication 242.It RekeyLimit 243.It SendEnv 244.It ServerAliveInterval 245.It ServerAliveCountMax 246.It SetEnv 247.It StrictHostKeyChecking 248.It TCPKeepAlive 249.It UpdateHostKeys 250.It User 251.It UserKnownHostsFile 252.It VerifyHostKeyDNS 253.El 254.It Fl P Ar port 255Specifies the port to connect to on the remote host. 256.It Fl p 257Preserves modification times, access times, and modes from the 258original files transferred. 259.It Fl q 260Quiet mode: disables the progress meter as well as warning and 261diagnostic messages from 262.Xr ssh 1 . 263.It Fl R Ar num_requests 264Specify how many requests may be outstanding at any one time. 265Increasing this may slightly improve file transfer speed 266but will increase memory usage. 267The default is 64 outstanding requests. 268.It Fl r 269Recursively copy entire directories when uploading and downloading. 270Note that 271.Nm 272does not follow symbolic links encountered in the tree traversal. 273.It Fl S Ar program 274Name of the 275.Ar program 276to use for the encrypted connection. 277The program must understand 278.Xr ssh 1 279options. 280.It Fl s Ar subsystem | sftp_server 281Specifies the SSH2 subsystem or the path for an sftp server 282on the remote host. 283A path is useful when the remote 284.Xr sshd 8 285does not have an sftp subsystem configured. 286.It Fl v 287Raise logging level. 288This option is also passed to ssh. 289.El 290.Sh INTERACTIVE COMMANDS 291Once in interactive mode, 292.Nm 293understands a set of commands similar to those of 294.Xr ftp 1 . 295Commands are case insensitive. 296Pathnames that contain spaces must be enclosed in quotes. 297Any special characters contained within pathnames that are recognized by 298.Xr glob 3 299must be escaped with backslashes 300.Pq Sq \e . 301.Bl -tag -width Ds 302.It Ic bye 303Quit 304.Nm sftp . 305.It Ic cd Op Ar path 306Change remote directory to 307.Ar path . 308If 309.Ar path 310is not specified, then change directory to the one the session started in. 311.It Ic chgrp Ar grp Ar path 312Change group of file 313.Ar path 314to 315.Ar grp . 316.Ar path 317may contain 318.Xr glob 7 319characters and may match multiple files. 320.Ar grp 321must be a numeric GID. 322.It Ic chmod Ar mode Ar path 323Change permissions of file 324.Ar path 325to 326.Ar mode . 327.Ar path 328may contain 329.Xr glob 7 330characters and may match multiple files. 331.It Ic chown Ar own Ar path 332Change owner of file 333.Ar path 334to 335.Ar own . 336.Ar path 337may contain 338.Xr glob 7 339characters and may match multiple files. 340.Ar own 341must be a numeric UID. 342.It Xo Ic df 343.Op Fl hi 344.Op Ar path 345.Xc 346Display usage information for the filesystem holding the current directory 347(or 348.Ar path 349if specified). 350If the 351.Fl h 352flag is specified, the capacity information will be displayed using 353"human-readable" suffixes. 354The 355.Fl i 356flag requests display of inode information in addition to capacity information. 357This command is only supported on servers that implement the 358.Dq statvfs@openssh.com 359extension. 360.It Ic exit 361Quit 362.Nm sftp . 363.It Xo Ic get 364.Op Fl afPpr 365.Ar remote-path 366.Op Ar local-path 367.Xc 368Retrieve the 369.Ar remote-path 370and store it on the local machine. 371If the local 372path name is not specified, it is given the same name it has on the 373remote machine. 374.Ar remote-path 375may contain 376.Xr glob 7 377characters and may match multiple files. 378If it does and 379.Ar local-path 380is specified, then 381.Ar local-path 382must specify a directory. 383.Pp 384If the 385.Fl a 386flag is specified, then attempt to resume partial transfers of existing files. 387Note that resumption assumes that any partial copy of the local file matches 388the remote copy. 389If the remote file contents differ from the partial local copy then the 390resultant file is likely to be corrupt. 391.Pp 392If the 393.Fl f 394flag is specified, then 395.Xr fsync 2 396will be called after the file transfer has completed to flush the file 397to disk. 398.Pp 399If either the 400.Fl P 401or 402.Fl p 403flag is specified, then full file permissions and access times are 404copied too. 405.Pp 406If the 407.Fl r 408flag is specified then directories will be copied recursively. 409Note that 410.Nm 411does not follow symbolic links when performing recursive transfers. 412.It Ic help 413Display help text. 414.It Ic lcd Op Ar path 415Change local directory to 416.Ar path . 417If 418.Ar path 419is not specified, then change directory to the local user's home directory. 420.It Ic lls Op Ar ls-options Op Ar path 421Display local directory listing of either 422.Ar path 423or current directory if 424.Ar path 425is not specified. 426.Ar ls-options 427may contain any flags supported by the local system's 428.Xr ls 1 429command. 430.Ar path 431may contain 432.Xr glob 7 433characters and may match multiple files. 434.It Ic lmkdir Ar path 435Create local directory specified by 436.Ar path . 437.It Xo Ic ln 438.Op Fl s 439.Ar oldpath 440.Ar newpath 441.Xc 442Create a link from 443.Ar oldpath 444to 445.Ar newpath . 446If the 447.Fl s 448flag is specified the created link is a symbolic link, otherwise it is 449a hard link. 450.It Ic lpwd 451Print local working directory. 452.It Xo Ic ls 453.Op Fl 1afhlnrSt 454.Op Ar path 455.Xc 456Display a remote directory listing of either 457.Ar path 458or the current directory if 459.Ar path 460is not specified. 461.Ar path 462may contain 463.Xr glob 7 464characters and may match multiple files. 465.Pp 466The following flags are recognized and alter the behaviour of 467.Ic ls 468accordingly: 469.Bl -tag -width Ds 470.It Fl 1 471Produce single columnar output. 472.It Fl a 473List files beginning with a dot 474.Pq Sq \&. . 475.It Fl f 476Do not sort the listing. 477The default sort order is lexicographical. 478.It Fl h 479When used with a long format option, use unit suffixes: Byte, Kilobyte, 480Megabyte, Gigabyte, Terabyte, Petabyte, and Exabyte in order to reduce 481the number of digits to four or fewer using powers of 2 for sizes (K=1024, 482M=1048576, etc.). 483.It Fl l 484Display additional details including permissions 485and ownership information. 486.It Fl n 487Produce a long listing with user and group information presented 488numerically. 489.It Fl r 490Reverse the sort order of the listing. 491.It Fl S 492Sort the listing by file size. 493.It Fl t 494Sort the listing by last modification time. 495.El 496.It Ic lumask Ar umask 497Set local umask to 498.Ar umask . 499.It Ic mkdir Ar path 500Create remote directory specified by 501.Ar path . 502.It Ic progress 503Toggle display of progress meter. 504.It Xo Ic put 505.Op Fl afPpr 506.Ar local-path 507.Op Ar remote-path 508.Xc 509Upload 510.Ar local-path 511and store it on the remote machine. 512If the remote path name is not specified, it is given the same name it has 513on the local machine. 514.Ar local-path 515may contain 516.Xr glob 7 517characters and may match multiple files. 518If it does and 519.Ar remote-path 520is specified, then 521.Ar remote-path 522must specify a directory. 523.Pp 524If the 525.Fl a 526flag is specified, then attempt to resume partial 527transfers of existing files. 528Note that resumption assumes that any partial copy of the remote file 529matches the local copy. 530If the local file contents differ from the remote local copy then 531the resultant file is likely to be corrupt. 532.Pp 533If the 534.Fl f 535flag is specified, then a request will be sent to the server to call 536.Xr fsync 2 537after the file has been transferred. 538Note that this is only supported by servers that implement 539the "fsync@openssh.com" extension. 540.Pp 541If either the 542.Fl P 543or 544.Fl p 545flag is specified, then full file permissions and access times are 546copied too. 547.Pp 548If the 549.Fl r 550flag is specified then directories will be copied recursively. 551Note that 552.Nm 553does not follow symbolic links when performing recursive transfers. 554.It Ic pwd 555Display remote working directory. 556.It Ic quit 557Quit 558.Nm sftp . 559.It Xo Ic reget 560.Op Fl Ppr 561.Ar remote-path 562.Op Ar local-path 563.Xc 564Resume download of 565.Ar remote-path . 566Equivalent to 567.Ic get 568with the 569.Fl a 570flag set. 571.It Xo Ic reput 572.Op Fl Ppr 573.Op Ar local-path 574.Ar remote-path 575.Xc 576Resume upload of 577.Op Ar local-path . 578Equivalent to 579.Ic put 580with the 581.Fl a 582flag set. 583.It Ic rename Ar oldpath Ar newpath 584Rename remote file from 585.Ar oldpath 586to 587.Ar newpath . 588.It Ic rm Ar path 589Delete remote file specified by 590.Ar path . 591.It Ic rmdir Ar path 592Remove remote directory specified by 593.Ar path . 594.It Ic symlink Ar oldpath Ar newpath 595Create a symbolic link from 596.Ar oldpath 597to 598.Ar newpath . 599.It Ic version 600Display the 601.Nm 602protocol version. 603.It Ic \&! Ns Ar command 604Execute 605.Ar command 606in local shell. 607.It Ic \&! 608Escape to local shell. 609.It Ic \&? 610Synonym for help. 611.El 612.Sh SEE ALSO 613.Xr ftp 1 , 614.Xr ls 1 , 615.Xr scp 1 , 616.Xr ssh 1 , 617.Xr ssh-add 1 , 618.Xr ssh-keygen 1 , 619.Xr ssh_config 5 , 620.Xr glob 7 , 621.Xr sftp-server 8 , 622.Xr sshd 8 623.Rs 624.%A T. Ylonen 625.%A S. Lehtinen 626.%T "SSH File Transfer Protocol" 627.%N draft-ietf-secsh-filexfer-00.txt 628.%D January 2001 629.%O work in progress material 630.Re 631