1.\" $OpenBSD: ftp.1,v 1.102 2016/07/28 21:37:45 tedu Exp $ 2.\" $NetBSD: ftp.1,v 1.22 1997/08/18 10:20:22 lukem Exp $ 3.\" 4.\" Copyright (c) 1985, 1989, 1990, 1993 5.\" The Regents of the University of California. All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 3. Neither the name of the University nor the names of its contributors 16.\" may be used to endorse or promote products derived from this software 17.\" without specific prior written permission. 18.\" 19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29.\" SUCH DAMAGE. 30.\" 31.\" @(#)ftp.1 8.3 (Berkeley) 10/9/94 32.\" 33.Dd $Mdocdate: July 28 2016 $ 34.Dt FTP 1 35.Os 36.Sh NAME 37.Nm ftp 38.Nd Internet file transfer program 39.Sh SYNOPSIS 40.Nm ftp 41.Op Fl 46AadEegiMmnptVv 42.Op Fl D Ar title 43.Op Fl k Ar seconds 44.Op Fl P Ar port 45.Op Fl r Ar seconds 46.Op Fl s Ar srcaddr 47.Op Ar host Op Ar port 48.Nm ftp 49.Op Fl C 50.Op Fl o Ar output 51.Op Fl s Ar srcaddr 52.Sm off 53.Pf ftp:// Op Ar user : password No @ 54.Ar host Op : Ar port 55.No / Ar file Op / 56.Sm on 57.Ar ... 58.Nm ftp 59.Op Fl C 60.Op Fl c Ar cookie 61.Op Fl o Ar output 62.Op Fl S Ar ssl_options 63.Op Fl s Ar srcaddr 64.Op Fl U Ar useragent 65.Sm off 66.Pf http Oo s Oc :// 67.Op Ar user : password No @ 68.Ar host Op : Ar port 69.No / Ar file 70.Sm on 71.Ar ... 72.Nm ftp 73.Op Fl C 74.Op Fl o Ar output 75.Op Fl s Ar srcaddr 76.Pf file: Ar 77.Nm ftp 78.Op Fl C 79.Op Fl o Ar output 80.Op Fl s Ar srcaddr 81.Ar host : Ns / Ns Ar file Ns Op / 82.Ar ... 83.Sh DESCRIPTION 84.Nm 85is the user interface to the Internet standard File Transfer 86Protocol (FTP). 87The program allows a user to transfer files to and from a 88remote network site. 89.Pp 90The latter four usage formats will fetch a file using either the 91FTP, HTTP, or HTTPS protocols into the current directory. 92This is ideal for scripts. 93Refer to 94.Sx AUTO-FETCHING FILES 95below for more information. 96.Pp 97The options are as follows: 98.Bl -tag -width Ds 99.It Fl 4 100Forces 101.Nm 102to use IPv4 addresses only. 103.It Fl 6 104Forces 105.Nm 106to use IPv6 addresses only. 107.It Fl A 108Force active mode FTP. 109By default, 110.Nm 111will try to use passive mode FTP and fall back to active mode 112if passive is not supported by the server. 113This option causes 114.Nm 115to always use an active connection. 116It is only useful for connecting 117to very old servers that do not implement passive mode properly. 118.It Fl a 119Causes 120.Nm 121to bypass the normal login procedure and use an anonymous login instead. 122.It Fl C 123Continue a previously interrupted file transfer. 124.Nm 125will continue transferring from an offset equal to the length of 126.Ar file . 127.Pp 128Resuming HTTP(S) transfers are only supported 129if the remote server supports the 130.Dq Range 131header. 132.It Fl c Ar cookie 133Load a Netscape-like cookiejar file 134for HTTP and HTTPS transfers. 135With this option relevant cookies from the jar are sent with each HTTP(S) 136request. 137Setting the 138.Ev http_cookies 139environment variable has the same effect. 140If both the 141.Ev http_cookies 142environment variable is set and the 143.Fl c 144argument is given, the latter takes precedence. 145.It Fl D Ar title 146Specify a short 147.Ar title 148for the start of the progress bar. 149.It Fl d 150Enables debugging. 151.It Fl E 152Disables EPSV/EPRT command on IPv4 connections. 153.It Fl e 154Disables command line editing. 155Useful for Emacs ange-ftp. 156.It Fl g 157Disables file name globbing. 158.It Fl i 159Turns off interactive prompting during 160multiple file transfers. 161.It Fl k Ar seconds 162When greater than zero, 163sends a byte after each 164.Ar seconds 165period over the control connection during long transfers, 166so that incorrectly configured network equipment won't 167aggressively drop it. 168The FTP protocol supports a 169.Dv NOOP 170command that can be used for that purpose. 171This assumes the FTP server can deal with extra commands coming over 172the control connection during a transfer. 173Well-behaved servers queue those commands, and process them after the 174transfer. 175By default, 176.Nm 177will send a byte every 60 seconds. 178.It Fl M 179Causes 180.Nm 181to never display the progress meter in cases where it would do 182so by default. 183.It Fl m 184Causes 185.Nm 186to always display the progress meter in cases where it would not do 187so by default. 188.It Fl n 189Restrains 190.Nm 191from attempting 192.Dq auto-login 193upon initial connection. 194If auto-login is enabled, 195.Nm 196will check the 197.Pa .netrc 198file (see below) in the user's home directory for an entry describing 199an account on the remote machine. 200If no entry exists, 201.Nm 202will prompt for the remote machine login name (default is the user 203identity on the local machine) and, if necessary, prompt for a password 204and an account with which to log in. 205.It Fl o Ar output 206When fetching a single file or URL, save the contents in 207.Ar output . 208To make the contents go to stdout, 209use 210.Sq - 211for 212.Ar output . 213.It Fl P Ar port 214Sets the port number to 215.Ar port . 216.It Fl p 217Enable passive mode operation for use behind connection filtering firewalls. 218This option has been deprecated as 219.Nm 220now tries to use passive mode by default, falling back to active mode 221if the server does not support passive connections. 222.It Fl r Ar seconds 223Retry to connect if failed, pausing for number of 224.Ar seconds . 225.It Fl S Ar ssl_options 226SSL/TLS options to use with HTTPS transfers. 227The following settings are available: 228.Bl -tag -width Ds 229.It Cm cafile Ns = Ns Ar /path/to/cert.pem 230PEM encoded file containing CA certificates used for certificate 231validation. 232.It Cm capath Ns = Ns Ar /path/to/certs/ 233Directory containing PEM encoded CA certificates used for certificate 234validation. 235Such a directory can be prepared using the c_rehash script distributed with 236OpenSSL. 237.It Cm ciphers Ns = Ns Ar cipher_list 238Specify the list of ciphers that will be used by 239.Nm . 240See the 241.Xr openssl 1 242.Cm ciphers 243subcommand. 244.It Cm depth Ns = Ns Ar max_depth 245Maximum depth of the certificate chain allowed when performing 246validation. 247.It Cm do 248Perform server certificate validation. 249.It Cm dont 250Don't perform server certificate validation. 251.El 252.Pp 253By default, server certificate validation is performed, and if it fails 254.Nm 255will abort. 256If no 257.Cm cafile 258or 259.Cm capath 260setting is provided, 261.Pa /etc/ssl/cert.pem 262will be used. 263.It Fl s Ar srcaddr 264Use 265.Ar srcaddr 266on the local machine as the source address 267of the connection. 268Only useful on systems with more than one address. 269.It Fl t 270Enables packet tracing. 271.It Fl U Ar useragent 272Set 273.Ar useragent 274as the User-Agent for HTTP(S) URL requests. 275If not specified, the default User-Agent is 276.Dq OpenBSD ftp . 277.It Fl V 278Disable verbose mode, overriding the default of enabled when input 279is from a terminal. 280.It Fl v 281Enable verbose mode. 282This is the default if input is from a terminal. 283Forces 284.Nm 285to show all responses from the remote server, as well 286as report on data transfer statistics. 287.El 288.Pp 289The host with which 290.Nm 291is to communicate may be specified on the command line. 292If this is done, 293.Nm 294will immediately attempt to establish a connection to an 295FTP server on that host; otherwise, 296.Nm 297will enter its command interpreter and await instructions 298from the user. 299When 300.Nm 301is awaiting commands, the prompt 302.Dq ftp\*(Gt 303is provided to the user. 304The following commands are recognized 305by 306.Nm : 307.Bl -tag -width Fl 308.It Ic \&! Oo Ar command 309.Op Ar arg ... 310.Oc 311Invoke an interactive shell on the local machine. 312If there are arguments, the first is taken to be a command to execute 313directly, with the rest of the arguments as its arguments. 314.It Ic \&$ Ar macro-name Op Ar arg ... 315Execute the macro 316.Ar macro-name 317that was defined with the 318.Ic macdef 319command. 320Arguments are passed to the macro unglobbed. 321.It Ic \&? Op Ar command 322A synonym for 323.Ic help . 324.It Ic account Op Ar password 325Supply a supplemental password required by a remote system for access 326to resources once a login has been successfully completed. 327If no argument is included, the user will be prompted for an account 328password in a non-echoing input mode. 329.It Ic append Ar local-file Op Ar remote-file 330Append a local file to a file on the remote machine. 331If 332.Ar remote-file 333is left unspecified, the local file name is used in naming the 334remote file after being altered by any 335.Ic ntrans 336or 337.Ic nmap 338setting. 339File transfer uses the current settings for 340.Ic type , 341.Ic format , 342.Ic mode , 343and 344.Ic structure . 345.It Ic ascii 346Set the file transfer 347.Ic type 348to network 349.Tn ASCII . 350.It Ic bell Op Ic on | off 351Arrange that a bell be sounded after each file transfer 352command is completed. 353.It Ic binary 354Set the file transfer 355.Ic type 356to support binary image transfer. 357This is the default type. 358.It Ic bye 359Terminate the FTP session with the remote server and exit 360.Nm . 361An end-of-file will also terminate the session and exit. 362.It Ic case Op Ic on | off 363Toggle remote computer file name case mapping during 364.Ic mget 365commands. 366When 367.Ic case 368is on (default is off), remote computer file names with all letters in 369upper case are written in the local directory with the letters mapped 370to lower case. 371.It Ic cd Ar remote-directory 372Change the working directory on the remote machine 373to 374.Ar remote-directory . 375.It Ic cdup 376Change the remote machine working directory to the parent of the 377current remote machine working directory. 378.It Ic chmod Ar mode file 379Change the permission modes of 380.Ar file 381on the remote 382system to 383.Ar mode . 384.It Ic close 385Terminate the FTP session with the remote server and 386return to the command interpreter. 387Any defined macros are erased. 388.It Ic cr Op Ic on | off 389Toggle carriage return stripping during 390ASCII type file retrieval. 391Records are denoted by a carriage return/linefeed sequence 392during ASCII type file transfer. 393When 394.Ic cr 395is on (the default), carriage returns are stripped from this 396sequence to conform with the 397.Ux 398single linefeed record delimiter. 399Records on non-UNIX 400remote systems may contain single linefeeds; 401when an ASCII type transfer is made, these linefeeds may be 402distinguished from a record delimiter only when 403.Ic cr 404is off. 405.It Ic debug Oo Ic on | off | 406.Ar debuglevel 407.Oc 408Toggle debugging mode. 409If an optional 410.Ar debuglevel 411is specified, it is used to set the debugging level. 412When debugging is on, 413.Nm 414prints each command sent to the remote machine, 415preceded by the string 416.Ql --\*(Gt . 417.It Ic delete Ar remote-file 418Delete the file 419.Ar remote-file 420on the remote machine. 421.It Ic dir Op Ar remote-directory Op Ar local-file 422A synonym for 423.Ic ls . 424.It Ic disconnect 425A synonym for 426.Ic close . 427.It Ic edit Op Ic on | off 428Toggle command line editing, and context sensitive command and file 429completion. 430This is automatically enabled if input is from a terminal, and 431disabled otherwise. 432.It Ic epsv4 Op Ic on | off 433Toggle use of EPSV/EPRT command on IPv4 connection. 434.It Ic exit 435A synonym for 436.Ic bye . 437.It Ic form Ar format 438Set the file transfer 439.Ic form 440to 441.Ar format . 442The default format is 443.Dq file . 444.It Ic ftp Ar host Op Ar port 445A synonym for 446.Ic open . 447.It Ic gate Oo Ic on | off | 448.Ar host Op Ar port 449.Oc 450Toggle gate-ftp mode. 451This will not be permitted if the gate-ftp server hasn't been set 452(either explicitly by the user, or from the 453.Ev FTPSERVER 454environment variable). 455If 456.Ar host 457is given, 458then gate-ftp mode will be enabled, and the gate-ftp server will be set to 459.Ar host . 460If 461.Ar port 462is also given, that will be used as the port to connect to on the 463gate-ftp server. 464.It Ic get Ar remote-file Op Ar local-file 465Retrieve the 466.Ar remote-file 467and store it on the local machine. 468If the local 469file name is not specified, it is given the same 470name it has on the remote machine, subject to 471alteration by the current 472.Ic case , 473.Ic ntrans , 474and 475.Ic nmap 476settings. 477The current settings for 478.Ic type , 479.Ic form , 480.Ic mode , 481and 482.Ic structure 483are used while transferring the file. 484.It Ic glob Op Ic on | off 485Toggle filename expansion for 486.Ic mdelete , 487.Ic mget 488and 489.Ic mput . 490If globbing is turned off with 491.Ic glob , 492the file name arguments 493are taken literally and not expanded. 494Globbing for 495.Ic mput 496is done as in 497.Xr csh 1 . 498For 499.Ic mdelete 500and 501.Ic mget , 502each remote file name is expanded 503separately on the remote machine and the lists are not merged. 504Expansion of a directory name is likely to be 505different from expansion of the name of an ordinary file: 506the exact result depends on the foreign operating system and FTP server, 507and can be previewed by doing 508.Dq mls remote-files - . 509Note: 510.Ic mget 511and 512.Ic mput 513are not meant to transfer 514entire directory subtrees of files. 515That can be done by 516transferring a 517.Xr tar 1 518archive of the subtree (in binary mode). 519.It Ic hash Oo Ic on | off | 520.Ar size 521.Oc 522Toggle hash mark 523.Pq Ql # 524printing for each data block transferred. 525The size of a data block defaults to 1024 bytes. 526This can be changed by specifying 527.Ar size 528in bytes. 529.It Ic help Op Ar command 530Print an informative message about the meaning of 531.Ar command . 532If no argument is given, 533.Nm 534prints a list of the known commands. 535.It Ic idle Op Ar seconds 536Set the inactivity timer on the remote server to 537.Ar seconds 538seconds. 539If 540.Ar seconds 541is omitted, the current inactivity timer is printed. 542.It Ic lcd Op Ar local-directory 543Change the working directory on the local machine. 544If 545no 546.Ar local-directory 547is specified, the user's home directory is used. 548.It Ic less Ar file 549A synonym for 550.Ic page . 551.It Ic lpwd 552Print the working directory on the local machine. 553.It Ic ls Op Ar remote-directory Op Ar local-file 554Print a listing of the contents of a directory on the remote machine. 555The listing includes any system-dependent information that the server 556chooses to include; for example, most 557.Ux 558systems will produce output from the command 559.Ql ls -l . 560If 561.Ar remote-directory 562is left unspecified, the current working directory is used. 563If interactive prompting is on, 564.Nm 565will prompt the user to verify that the last argument is indeed the 566target local file for receiving 567.Ic ls 568output. 569If no local file is specified, or if 570.Ar local-file 571is 572.Sq - , 573the output is sent to the terminal. 574.It Ic macdef Ar macro-name 575Define a macro. 576Subsequent lines are stored as the macro 577.Ar macro-name ; 578a null line (consecutive newline characters 579in a file or 580carriage returns from the terminal) terminates macro input mode. 581There is a limit of 16 macros and 4096 total characters in all 582defined macros. 583Macro names can be a maximum of 8 characters. 584Macros are only applicable to the current session they are 585defined in (or if defined outside a session, to the session 586invoked with the next 587.Ic open 588command), and remain defined until a 589.Ic close 590command is executed. 591To invoke a macro, 592use the 593.Ic $ 594command (see above). 595.Pp 596The macro processor interprets 597.Ql $ 598and 599.Ql \e 600as special characters. 601A 602.Ql $ 603followed by a number (or numbers) is replaced by the 604corresponding argument on the macro invocation command line. 605A 606.Ql $ 607followed by an 608.Sq i 609tells the macro processor that the 610executing macro is to be looped. 611On the first pass 612.Ql $i 613is 614replaced by the first argument on the macro invocation command line, 615on the second pass it is replaced by the second argument, and so on. 616A 617.Ql \e 618followed by any character is replaced by that character. 619Use the 620.Ql \e 621to prevent special treatment of the 622.Ql $ . 623.It Ic mdelete Op Ar remote-files 624Delete the 625.Ar remote-files 626on the remote machine. 627.It Ic mdir Ar remote-files local-file 628A synonym for 629.Ic mls . 630.It Xo Ic mget 631.Op Fl cnr 632.Op Fl d Ar depth 633.Ar remote-files 634.Xc 635Expand the 636.Ar remote-files 637on the remote machine 638and do a 639.Ic get 640for each file name thus produced. 641See 642.Ic glob 643for details on the filename expansion. 644Resulting file names will then be processed according to 645.Ic case , 646.Ic ntrans , 647and 648.Ic nmap 649settings. 650Files are transferred into the local working directory, 651which can be changed with 652.Ql lcd directory ; 653new local directories can be created with 654.Ql "\&! mkdir directory" . 655.Pp 656The options are as follows: 657.Bl -tag -width Ds 658.It Fl c 659Use 660.Ic reget 661instead of 662.Ic get . 663.It Fl d Ar depth 664Specify the maximum recursion level 665.Ar depth . 666The default is 0, which means unlimited. 667.It Fl n 668Use 669.Ic newer 670instead of 671.Ic get . 672.It Fl r 673Recursively descend the directory tree, transferring all files and 674directories. 675.El 676.It Ic mkdir Ar directory-name 677Make a directory on the remote machine. 678.It Ic mls Ar remote-files local-file 679Like 680.Ic ls , 681except multiple remote files may be specified, 682and the 683.Ar local-file 684must be specified. 685If interactive prompting is on, 686.Nm 687will prompt the user to verify that the last argument is indeed the 688target local file for receiving 689.Ic mls 690output. 691.It Ic mode Op Ar mode-name 692Set the file transfer 693.Ic mode 694to 695.Ar mode-name . 696The default mode is 697.Dq stream 698mode. 699.It Ic modtime Ar file 700Show the last modification time of 701.Ar file 702on the remote machine. 703.It Ic more Ar file 704A synonym for 705.Ic page . 706.It Xo Ic mput 707.Op Fl cr 708.Op Fl d Ar depth 709.Ar local-files 710.Xc 711Expand wild cards in the list of local files given as arguments 712and do a 713.Ic put 714for each file in the resulting list. 715See 716.Ic glob 717for details of filename expansion. 718Resulting file names will then be processed according to 719.Ic ntrans 720and 721.Ic nmap 722settings. 723.Pp 724If the 725.Fl c 726flag is specified then 727The options are as follows: 728.Bl -tag -width Ds 729.It Fl c 730Use 731.Ic reput 732instead of 733.Ic put . 734.It Fl d Ar depth 735Specify the maximum recursion level 736.Ar depth . 737The default is 0, which means unlimited. 738.It Fl r 739Recursively descend the directory tree, transferring all files and 740directories. 741.El 742.It Xo Ic msend 743.Op Fl c 744.Ar local-files 745.Xc 746A synonym for 747.Ic mput . 748.It Ic newer Ar remote-file Op Ar local-file 749Get the file only if the modification time of the remote file is more 750recent than the file on the current system. 751If the file does not 752exist on the current system, the remote file is considered 753.Ic newer . 754Otherwise, this command is identical to 755.Ar get . 756.It Ic nlist Op Ar remote-directory Op Ar local-file 757Print a list of the files in a 758directory on the remote machine. 759If 760.Ar remote-directory 761is left unspecified, the current working directory is used. 762If interactive prompting is on, 763.Nm 764will prompt the user to verify that the last argument is indeed the 765target local file for receiving 766.Ic nlist 767output. 768If no local file is specified, or if 769.Ar local-file 770is 771.Sq - , 772the output is sent to the terminal. 773Note that on some servers, the 774.Ic nlist 775command will only return information on normal files (not directories 776or special files). 777.It Ic nmap Op Ar inpattern outpattern 778Set or unset the filename mapping mechanism. 779If no arguments are specified, the filename mapping mechanism is unset. 780If arguments are specified, remote filenames are mapped during 781.Ic mput 782commands and 783.Ic put 784commands issued without a specified remote target filename. 785If arguments are specified, local filenames are mapped during 786.Ic mget 787commands and 788.Ic get 789commands issued without a specified local target filename. 790This command is useful when connecting to a non-UNIX remote computer 791with different file naming conventions or practices. 792.Pp 793The mapping follows the pattern set by 794.Ar inpattern 795and 796.Ar outpattern . 797.Ar inpattern 798is a template for incoming filenames (which may have already been 799processed according to the 800.Ic ntrans 801and 802.Ic case 803settings). 804Variable templating is accomplished by including the 805sequences 806.Ql $1 , 807.Ql $2 , 808\&..., 809.Ql $9 810in 811.Ar inpattern . 812Use 813.Ql \e 814to prevent this special treatment of the 815.Ql $ 816character. 817All other characters are treated literally, and are used to determine the 818.Ic nmap 819.Ar inpattern 820variable values. 821.Pp 822For example, given 823.Ar inpattern 824$1.$2 and the remote file name "mydata.data", $1 would have the value 825"mydata", and $2 would have the value "data". 826The 827.Ar outpattern 828determines the resulting mapped filename. 829The sequences 830.Ql $1 , 831.Ql $2 , 832\&..., 833.Ql $9 834are replaced by any value resulting from the 835.Ar inpattern 836template. 837The sequence 838.Ql $0 839is replaced by the original filename. 840Additionally, the sequence 841.Sq Op Ar seq1 , Ar seq2 842is replaced by 843.Ar seq1 844if 845.Ar seq1 846is not a null string; otherwise it is replaced by 847.Ar seq2 . 848For example: 849.Pp 850.Dl nmap $1.$2.$3 [$1,$2].[$2,file] 851.Pp 852This command would yield the output filename 853.Pa myfile.data 854for input filenames 855.Pa myfile.data 856and 857.Pa myfile.data.old ; 858.Pa myfile.file 859for the input filename 860.Pa myfile ; 861and 862.Pa myfile.myfile 863for the input filename 864.Pa .myfile . 865Spaces may be included in 866.Ar outpattern 867by quoting them, 868as in the following example: 869.Bd -literal -offset indent 870nmap $1.$2 "$1 $2" 871.Ed 872.Pp 873Use the 874.Ql \e 875character to prevent special treatment 876of the 877.Ql $ , 878.Ql \&[ , 879.Ql \&] , 880and 881.Ql \&, 882characters. 883.It Ic ntrans Op Ar inchars Op Ar outchars 884Set or unset the filename character translation mechanism. 885If no arguments are specified, the filename character 886translation mechanism is unset. 887If arguments are specified, characters in 888remote filenames are translated during 889.Ic mput 890commands and 891.Ic put 892commands issued without a specified remote target filename. 893If arguments are specified, characters in 894local filenames are translated during 895.Ic mget 896commands and 897.Ic get 898commands issued without a specified local target filename. 899This command is useful when connecting to a non-UNIX remote computer 900with different file naming conventions or practices. 901Characters in a filename matching a character in 902.Ar inchars 903are replaced with the corresponding character in 904.Ar outchars . 905If the character's position in 906.Ar inchars 907is longer than the length of 908.Ar outchars , 909the character is deleted from the file name. 910.It Ic open Ar host Op Ar port 911Establish a connection to the specified 912.Ar host 913FTP server. 914An optional port number may be supplied, 915in which case 916.Nm 917will attempt to contact an FTP server at that port. 918If the 919.Ic auto-login 920option is on (default), 921.Nm 922will also attempt to automatically log the user in to 923the FTP server (see below). 924.It Ic page Ar file 925Retrieve 926.Ic file 927and display with the program defined in 928.Ev PAGER 929(defaulting to 930.Xr more 1 931if 932.Ev PAGER 933is null or not defined). 934.It Ic passive Op Ic on | off 935Toggle passive mode. 936If passive mode is turned on (default is on), 937.Nm 938will send a 939.Dv EPSV 940command for all data connections instead of the usual 941.Dv PORT 942command. 943The 944.Dv PASV 945command requests that the remote server open a port for the data connection 946and return the address of that port. 947The remote server listens on that port and the client connects to it. 948When using the more traditional 949.Dv PORT 950command, the client listens on a port and sends that address to the remote 951server, who connects back to it. 952Passive mode is useful when using 953.Nm 954through a gateway router or host that controls the directionality of 955traffic. 956(Note that though FTP servers are required to support the 957.Dv PASV 958command by RFC 1123, some do not.) 959.It Ic preserve Op Ic on | off 960Toggle preservation of modification times on retrieved files. 961.It Ic progress Op Ic on | off 962Toggle display of transfer progress bar. 963The progress bar will be disabled for a transfer that has 964.Ar local-file 965as 966.Sq - 967or a command that starts with 968.Sq \&| . 969Refer to 970.Sx FILE NAMING CONVENTIONS 971for more information. 972.It Ic prompt Op Ic on | off 973Toggle interactive prompting. 974Interactive prompting 975occurs during multiple file transfers to allow the 976user to selectively retrieve or store files. 977If prompting is turned off (default is on), any 978.Ic mget 979or 980.Ic mput 981will transfer all files, and any 982.Ic mdelete 983will delete all files. 984.Pp 985When prompting is on, the following commands are available at a prompt: 986.Bl -tag -width 2n -offset indent 987.It Ic ?\& 988Print help message. 989.It Ic a 990Answer 991.Dq yes 992to the current file and automatically answer 993.Dq yes 994to any remaining files for the current command. 995.It Ic n 996Do not transfer the file. 997.It Ic p 998Answer 999.Dq yes 1000to the current file and turn off prompt mode 1001(as if 1002.Dq prompt off 1003had been given). 1004.It Ic q 1005Answer 1006.Dq no 1007to the current file and automatically answer 1008.Dq no 1009to any remaining files for the current command. 1010.It Ic y 1011Transfer the file. 1012.El 1013.It Ic proxy Ar command 1014Execute an FTP command on a secondary control connection. 1015This command allows simultaneous connection to two remote FTP 1016servers for transferring files between the two servers. 1017The first 1018.Ic proxy 1019command should be an 1020.Ic open , 1021to establish the secondary control connection. 1022Enter the command 1023.Ic proxy ?\& 1024to see other FTP commands executable on the 1025secondary connection. 1026The following commands behave differently when prefaced by 1027.Ic proxy : 1028.Ic open 1029will not define new macros during the auto-login process; 1030.Ic close 1031will not erase existing macro definitions; 1032.Ic get 1033and 1034.Ic mget 1035transfer files from the host on the primary control connection 1036to the host on the secondary control connection; and 1037.Ic put , 1038.Ic mput , 1039and 1040.Ic append 1041transfer files from the host on the secondary control connection 1042to the host on the primary control connection. 1043Third party file transfers depend upon support of the FTP protocol 1044.Dv PASV 1045command by the server on the secondary control connection. 1046.It Ic put Ar local-file Op Ar remote-file 1047Store a local file on the remote machine. 1048If 1049.Ar remote-file 1050is left unspecified, the local file name is used 1051after processing according to any 1052.Ic ntrans 1053or 1054.Ic nmap 1055settings 1056in naming the remote file. 1057File transfer uses the 1058current settings for 1059.Ic type , 1060.Ic format , 1061.Ic mode , 1062and 1063.Ic structure . 1064.It Ic pwd 1065Print the name of the current working directory on the remote 1066machine. 1067.It Ic quit 1068A synonym for 1069.Ic bye . 1070.It Ic quote Ar arg ... 1071The arguments specified are sent, verbatim, to the remote FTP server. 1072.It Ic recv Ar remote-file Op Ar local-file 1073A synonym for 1074.Ic get . 1075.It Ic reget Ar remote-file Op Ar local-file 1076Reget acts like get, except that if 1077.Ar local-file 1078exists and is 1079smaller than 1080.Ar remote-file , 1081.Ar local-file 1082is presumed to be 1083a partially transferred copy of 1084.Ar remote-file 1085and the transfer 1086is continued from the apparent point of failure. 1087This command 1088is useful when transferring very large files over networks that 1089are prone to dropping connections. 1090.It Ic rename Ar from-name to-name 1091Rename the file 1092.Ar from-name 1093on the remote machine to the file 1094.Ar to-name . 1095.It Ic reput Ar local-file Op Ar remote-file 1096Reput acts like put, except that if 1097.Ar remote-file 1098exists and is 1099smaller than 1100.Ar local-file , 1101.Ar remote-file 1102is presumed to be 1103a partially transferred copy of 1104.Ar local-file 1105and the transfer 1106is continued from the apparent point of failure. 1107This command 1108is useful when transferring very large files over networks that 1109are prone to dropping connections. 1110.It Ic reset 1111Clear reply queue. 1112This command re-synchronizes command/reply sequencing with the remote 1113FTP server. 1114Resynchronization may be necessary following a violation of the FTP protocol 1115by the remote server. 1116.It Ic restart Ar marker 1117Restart the immediately following 1118.Ic get 1119or 1120.Ic put 1121at the 1122indicated 1123.Ar marker . 1124On 1125.Ux 1126systems, 1127.Ar marker 1128is usually a byte 1129offset into the file. 1130.It Ic rhelp Op Ar command-name 1131Request help from the remote FTP server. 1132If a 1133.Ar command-name 1134is specified, it is supplied to the server as well. 1135.It Ic rmdir Ar directory-name 1136Delete a directory on the remote machine. 1137.It Ic rstatus Op Ar file 1138With no arguments, show status of remote machine. 1139If 1140.Ar file 1141is specified, show status of 1142.Ar file 1143on remote machine. 1144.It Ic runique Op Ic on | off 1145Toggle storing of files on the local system with unique filenames. 1146If a file already exists with a name equal to the target 1147local filename for a 1148.Ic get 1149or 1150.Ic mget 1151command, a 1152.Dq .1 1153is appended to the name. 1154If the resulting name matches another existing file, 1155a 1156.Dq .2 1157is appended to the original name. 1158If this process continues up to 1159.Dq .99 , 1160an error message is printed, and the transfer does not take place. 1161The generated unique filename will be reported. 1162Note that 1163.Ic runique 1164will not affect local files generated from a shell command 1165(see below). 1166The default value is off. 1167.It Ic send Ar local-file Op Ar remote-file 1168A synonym for 1169.Ic put . 1170.It Ic sendport Op Ic on | off 1171Toggle the use of 1172.Dv PORT 1173commands. 1174By default, 1175.Nm 1176will attempt to use a 1177.Dv PORT 1178command when establishing 1179a connection for each data transfer. 1180The use of 1181.Dv PORT 1182commands can prevent delays 1183when performing multiple file transfers. 1184If the 1185.Dv PORT 1186command fails, 1187.Nm 1188will use the default data port. 1189When the use of 1190.Dv PORT 1191commands is disabled, no attempt will be made to use 1192.Dv PORT 1193commands for each data transfer. 1194This is useful for certain FTP implementations which do ignore 1195.Dv PORT 1196commands but, incorrectly, indicate they've been accepted. 1197.It Ic site Ar arg ... 1198The arguments specified are sent, verbatim, to the remote FTP server as a 1199.Dv SITE 1200command. 1201.It Ic size Ar file 1202Return size of 1203.Ar file 1204on remote machine. 1205.It Ic status 1206Show the current status of 1207.Nm . 1208.\" .It Ic struct Op Ar struct-name 1209.\" Set the file transfer 1210.\" .Ar structure 1211.\" to 1212.\" .Ar struct-name . 1213.\" By default, 1214.\" .Dq file 1215.\" structure is used. 1216.It Ic sunique Op Ic on | off 1217Toggle storing of files on remote machine under unique file names. 1218The remote FTP server must support the FTP protocol 1219.Dv STOU 1220command for 1221successful completion. 1222The remote server will report the unique name. 1223Default value is off. 1224.It Ic system 1225Show the type of operating system running on the remote machine. 1226.It Ic trace Op Ic on | off 1227Toggle packet tracing. 1228.It Ic type Op Ar type-name 1229Set the file transfer 1230.Ic type 1231to 1232.Ar type-name . 1233If no type is specified, the current type 1234is printed. 1235The default type is 1236.Dq binary . 1237.It Ic umask Op Ar newmask 1238Set the default umask on the remote server to 1239.Ar newmask . 1240If 1241.Ar newmask 1242is omitted, the current umask is printed. 1243.It Xo 1244.Ic user Ar username 1245.Op Ar password Op Ar account 1246.Xc 1247Identify yourself to the remote FTP server. 1248If the 1249.Ar password 1250is not specified and the server requires it, 1251.Nm 1252will prompt the user for it (after disabling local echo). 1253If an 1254.Ar account 1255field is not specified, and the FTP server requires it, 1256the user will be prompted for it. 1257If an 1258.Ar account 1259field is specified, an account command will 1260be relayed to the remote server after the login sequence 1261is completed if the remote server did not require it 1262for logging in. 1263Unless 1264.Nm 1265is invoked with 1266.Dq auto-login 1267disabled, this process is done automatically on initial connection to the 1268FTP server. 1269.It Ic verbose Op Ic on | off 1270Toggle verbose mode. 1271In verbose mode, all responses from 1272the FTP server are displayed to the user. 1273In addition, 1274if verbose is on, when a file transfer completes, statistics 1275regarding the efficiency of the transfer are reported. 1276By default, 1277verbose is on. 1278.El 1279.Pp 1280Command arguments which have embedded spaces may be quoted with 1281quote 1282.Pq Ql \&" 1283marks. 1284.Pp 1285Commands which toggle settings can take an explicit 1286.Ic on 1287or 1288.Ic off 1289argument to force the setting appropriately. 1290.Pp 1291If 1292.Nm 1293receives a 1294.Dv SIGINFO 1295(see the 1296.Dq status 1297argument of 1298.Xr stty 1 ) 1299signal whilst a transfer is in progress, the current transfer rate 1300statistics will be written to the standard error output, in the 1301same format as the standard completion message. 1302.Sh AUTO-FETCHING FILES 1303In addition to standard commands, this version of 1304.Nm 1305supports an auto-fetch feature. 1306To enable auto-fetch, simply pass the list of hostnames/files 1307on the command line. 1308.Pp 1309The following formats are valid syntax for an auto-fetch element: 1310.Bl -tag -width Ds 1311.It Ar host : Ns / Ns Ar file Ns Op / 1312.Dq Classic 1313.Nm 1314format. 1315.Sm off 1316.It Xo 1317.Pf ftp:// Op Ar user : password No @ 1318.Ar host Op : Ar port 1319.No / Ar file Op / 1320.Xc 1321.Sm on 1322An FTP URL, retrieved using the FTP protocol if 1323.Ev ftp_proxy 1324isn't defined. 1325Otherwise, transfer using HTTP via the proxy defined in 1326.Ev ftp_proxy . 1327If a 1328.Ar user 1329and 1330.Ar password 1331are given and 1332.Ev ftp_proxy 1333isn't defined, 1334log in as 1335.Ar user 1336with a password of 1337.Ar password . 1338.Sm off 1339.It Xo 1340.Pf http:// Op Ar user : password No @ 1341.Ar host Op : Ar port 1342.No / Ar file 1343.Xc 1344.Sm on 1345An HTTP URL, retrieved using the HTTP protocol. 1346If 1347.Ev http_proxy 1348is defined, it is used as a URL to an HTTP proxy server. 1349If a 1350.Ar user 1351and 1352.Ar password 1353are given and 1354.Ev http_proxy 1355isn't defined, 1356log in as 1357.Ar user 1358with a password of 1359.Ar password 1360using Basic authentication. 1361.Sm off 1362.It Xo 1363.Pf https:// Op Ar user : password No @ 1364.Ar host Op : Ar port 1365.No / Ar file 1366.Xc 1367.Sm on 1368An HTTPS URL, retrieved using the HTTPS protocol. 1369If 1370.Ev http_proxy 1371is defined, this HTTPS proxy server will be used to fetch the 1372file using the CONNECT method. 1373If a 1374.Ar user 1375and 1376.Ar password 1377are given and 1378.Ev http_proxy 1379isn't defined, 1380log in as 1381.Ar user 1382with a password of 1383.Ar password 1384using Basic authentication. 1385.It Pf file: Ar file 1386.Ar file 1387is retrieved from a mounted file system. 1388.El 1389.Pp 1390If a classic format or an FTP URL format has a trailing 1391.Sq / , 1392then 1393.Nm 1394will connect to the site and 1395.Ic cd 1396to the directory given as the path, and leave the user in interactive 1397mode ready for further input. 1398.Pp 1399If successive auto-fetch FTP elements refer to the same host, then 1400the connection is maintained between transfers, reducing overhead on 1401connection creation and deletion. 1402.Pp 1403If 1404.Ar file 1405contains a glob character and globbing is enabled 1406(see 1407.Ic glob ) , 1408then the equivalent of 1409.Ic mget Ar file 1410is performed. 1411.Pp 1412If no 1413.Fl o 1414option is specified, and 1415the directory component of 1416.Ar file 1417contains no globbing characters, 1418then 1419it is stored in the current directory as the 1420.Xr basename 1 1421of 1422.Ar file . 1423If 1424.Fl o Ar output 1425is specified, then 1426.Ar file 1427is stored as 1428.Ar output . 1429Otherwise, the remote name is used as the local name. 1430.Sh ABORTING A FILE TRANSFER 1431To abort a file transfer, use the terminal interrupt key 1432(usually Ctrl-C). 1433Sending transfers will be immediately halted. 1434Receiving transfers will be halted by sending an FTP protocol 1435.Dv ABOR 1436command to the remote server, and discarding any further data received. 1437The speed at which this is accomplished depends upon the remote 1438server's support for 1439.Dv ABOR 1440processing. 1441If the remote server does not support the 1442.Dv ABOR 1443command, an 1444.Ql ftp\*(Gt 1445prompt will not appear until the remote server has completed 1446sending the requested file. 1447.Pp 1448The terminal interrupt key sequence will be ignored when 1449.Nm 1450has completed any local processing and is awaiting a reply 1451from the remote server. 1452A long delay in this mode may result from the ABOR processing described 1453above, or from unexpected behavior by the remote server, including 1454violations of the FTP protocol. 1455If the delay results from unexpected remote server behavior, the local 1456.Nm 1457program must be killed by hand. 1458.Sh FILE NAMING CONVENTIONS 1459Files specified as arguments to 1460.Nm 1461commands are processed according to the following rules. 1462.Bl -enum 1463.It 1464If 1465.Sq - 1466is specified as a local file name, the standard input (for reading) 1467or standard output (for writing) 1468is used. 1469.It 1470If the first character of a local file name is 1471.Sq \&| , 1472the 1473remainder of the argument is interpreted as a shell command. 1474.Nm 1475then forks a shell, using 1476.Xr popen 3 1477with the argument supplied, and reads (writes) from the standard output 1478(standard input). 1479If the shell command includes spaces, the argument 1480must be quoted; e.g., 1481.Qq ls -lt . 1482A particularly 1483useful example of this mechanism is: 1484.Qq ls \&. |more . 1485.It 1486Failing the above checks, if 1487.Dq globbing 1488is enabled, 1489local file names are expanded 1490according to the rules used in the 1491.Xr csh 1 1492.Ic glob 1493command. 1494If the 1495.Nm 1496command expects a single local file (e.g., 1497.Ic put ) , 1498only the first filename generated by the 1499.Dq globbing 1500operation is used. 1501.It 1502For 1503.Ic mget 1504commands and 1505.Ic get 1506commands with unspecified local file names, the local filename is 1507the remote filename, which may be altered by a 1508.Ic case , 1509.Ic ntrans , 1510or 1511.Ic nmap 1512setting. 1513The resulting filename may then be altered if 1514.Ic runique 1515is on. 1516.It 1517For 1518.Ic mput 1519commands and 1520.Ic put 1521commands with unspecified remote file names, the remote filename is 1522the local filename, which may be altered by a 1523.Ic ntrans 1524or 1525.Ic nmap 1526setting. 1527The resulting filename may then be altered by the remote server if 1528.Ic sunique 1529is on. 1530.El 1531.Sh FILE TRANSFER PARAMETERS 1532The FTP specification specifies many parameters which may 1533affect a file transfer. 1534The 1535.Ic type 1536may be one of 1537.Dq ascii , 1538.Dq binary , 1539or 1540.Dq image . 1541.Nm 1542supports the ASCII and image types of file transfer. 1543.Pp 1544.Nm 1545supports only the default values for the remaining 1546file transfer parameters: 1547.Ic mode , 1548.Ic form , 1549and 1550.Ic struct . 1551.Sh THE .netrc FILE 1552The 1553.Pa .netrc 1554file contains login and initialization information 1555used by the auto-login process. 1556It resides in the user's home directory. 1557The following tokens are recognized; they may be separated by spaces, 1558tabs, or new-lines: 1559.Bl -tag -width password 1560.It Ic machine Ar name 1561Identify a remote machine 1562.Ar name . 1563The auto-login process searches the 1564.Pa .netrc 1565file for a 1566.Ic machine 1567token that matches the remote machine specified on the 1568.Nm 1569command line or as an 1570.Ic open 1571command argument. 1572Once a match is made, the subsequent 1573.Pa .netrc 1574tokens are processed, 1575stopping when the end of file is reached or another 1576.Ic machine 1577or a 1578.Ic default 1579token is encountered. 1580.It Ic default 1581This is the same as 1582.Ic machine 1583.Ar name 1584except that 1585.Ic default 1586matches any name. 1587There can be only one 1588.Ic default 1589token, and it must be after all 1590.Ic machine 1591tokens. 1592This is normally used as: 1593.Pp 1594.Dl default login anonymous password user@site 1595.Pp 1596thereby giving the user 1597.Ar automatic 1598anonymous FTP login to 1599machines not specified in 1600.Pa .netrc . 1601This can be overridden 1602by using the 1603.Fl n 1604flag to disable auto-login. 1605.It Ic login Ar name 1606Identify a user on the remote machine. 1607If this token is present, the auto-login process will initiate 1608a login using the specified 1609.Ar name . 1610.It Ic password Ar string 1611Supply a password. 1612If this token is present, the auto-login process will supply the 1613specified string if the remote server requires a password as part 1614of the login process. 1615Note that if this token is present in the 1616.Pa .netrc 1617file for any user other 1618than 1619.Ar anonymous , 1620.Nm 1621will abort the auto-login process if the 1622.Pa .netrc 1623is readable by 1624anyone besides the user. 1625.It Ic account Ar string 1626Supply an additional account password. 1627If this token is present, the auto-login process will supply the 1628specified string if the remote server requires an additional 1629account password, or the auto-login process will initiate an 1630.Dv ACCT 1631command if it does not. 1632.It Ic macdef Ar name 1633Define a macro. 1634This token functions like the 1635.Nm 1636.Ic macdef 1637command functions. 1638A macro is defined with the specified name; its contents begin with the 1639next 1640.Pa .netrc 1641line and continue until a null line (consecutive new-line 1642characters) is encountered. 1643Like the other tokens in the 1644.Pa .netrc 1645file, a 1646.Ic macdef 1647is applicable only to the 1648.Ic machine 1649definition preceding it. 1650A 1651.Ic macdef 1652entry cannot be utilized by multiple 1653.Ic machine 1654definitions; rather, it must be defined following each 1655.Ic machine 1656it is intended to be used with. 1657If a macro named 1658.Ic init 1659is defined, it is automatically executed as the last step in the 1660auto-login process. 1661.El 1662.Sh COMMAND LINE EDITING 1663.Nm 1664supports interactive command line editing, via the 1665.Xr editline 3 1666library. 1667It is enabled with the 1668.Ic edit 1669command, and is enabled by default if input is from a tty. 1670Previous lines can be recalled and edited with the arrow keys, 1671and other GNU Emacs-style editing keys may be used as well. 1672.Pp 1673The 1674.Xr editline 3 1675library is configured with a 1676.Pa .editrc 1677file \- refer to 1678.Xr editrc 5 1679for more information. 1680.Pp 1681An extra key binding is available to 1682.Nm 1683to provide context sensitive command and filename completion 1684(including remote file completion). 1685To use this, bind a key to the 1686.Xr editline 3 1687command 1688.Ic ftp-complete . 1689By default, this is bound to the TAB key. 1690.Sh ENVIRONMENT 1691.Nm 1692utilizes the following environment variables: 1693.Bl -tag -width "FTPSERVERPORT" 1694.It Ev FTPMODE 1695Overrides the default operation mode. 1696Recognized values are: 1697.Pp 1698.Bl -tag -width "passive " -offset indent -compact 1699.It passive 1700passive mode FTP only 1701.It active 1702active mode FTP only 1703.It auto 1704automatic determination of passive or active (this is the default) 1705.It gate 1706gate-ftp mode 1707.El 1708.It Ev FTPSERVER 1709Host to use as gate-ftp server when 1710.Ic gate 1711is enabled. 1712.It Ev FTPSERVERPORT 1713Port to use when connecting to gate-ftp server when 1714.Ic gate 1715is enabled. 1716Default is port returned by a 1717.Fn getservbyname 1718lookup of 1719.Dq ftpgate/tcp . 1720.It Ev HOME 1721For default location of a 1722.Pa .netrc 1723file, if one exists. 1724.It Ev PAGER 1725Used by 1726.Ic page 1727to display files. 1728.It Ev SHELL 1729For default shell. 1730.It Ev ftp_proxy 1731URL of FTP proxy to use when making FTP URL requests 1732(if not defined, use the standard FTP protocol). 1733.It Ev http_proxy 1734URL of HTTP proxy to use when making HTTP or HTTPS URL requests. 1735.It Ev http_cookies 1736Path of a Netscape-like cookiejar file to use when making 1737HTTP or HTTPS URL requests. 1738.El 1739.Sh PORT ALLOCATION 1740For active mode data connections, 1741.Nm 1742will listen to a random high TCP port. 1743The interval of ports used are configurable using 1744.Xr sysctl 8 1745variables 1746.Va net.inet.ip.porthifirst 1747and 1748.Va net.inet.ip.porthilast . 1749.Sh SEE ALSO 1750.Xr basename 1 , 1751.Xr csh 1 , 1752.Xr more 1 , 1753.Xr stty 1 , 1754.Xr tar 1 , 1755.Xr tftp 1 , 1756.Xr editline 3 , 1757.Xr getservbyname 3 , 1758.Xr popen 3 , 1759.Xr editrc 5 , 1760.Xr services 5 , 1761.Xr ftp-proxy 8 , 1762.Xr ftpd 8 1763.Sh STANDARDS 1764.Rs 1765.%A J. Postel 1766.%A J. Reynolds 1767.%D October 1985 1768.%R RFC 959 1769.%T FILE TRANSFER PROTOCOL (FTP) 1770.Re 1771.Pp 1772.Rs 1773.%A P. Hethmon 1774.%D March 2007 1775.%R RFC 3659 1776.%T Extensions to FTP 1777.Re 1778.Sh HISTORY 1779The 1780.Nm 1781command appeared in 1782.Bx 4.2 . 1783.Sh BUGS 1784Correct execution of many commands depends upon proper behavior 1785by the remote server. 1786.Pp 1787In the recursive mode of 1788.Ic mget , 1789files and directories starting with whitespace are ignored 1790because the list cannot be parsed any other way. 1791