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