Linux ftp command
The ftp command runs the classical command-line file transfer client, FTP. It’s an interactive text user interface for using the ARPANET (Advanced Research Projects Agency Network) standard File Transfer Protocol. It can transfer files to and from a remote network.
This page describes the version of ftp provided by package management on many GNU/Linux operating systems.
Syntax
ftp [-46pinegvd] [host [port]]
Options
-4 | Use only IPv4 to contact any host. |
-6 | Use IPv6 only. |
-p | Use passive mode for data transfers. Allows use of ftp in environments where a firewall prevents connections from the outside world back to the client machine. Requires that the ftp server support the PASV command. This is the default if invoked as pftp. |
-i | Turns off interactive prompting during multiple file transfers. |
-n | Restrains ftp from attempting «auto-login» upon initial connection. If auto-login is enabled, ftp checks the .netrc (see netrc) file in the user’s home directory for an entry describing an account on the remote machine. If no entry exists, ftp prompts for the remote machine login name (default is the user identity on the local machine), and, if necessary, prompt for a password and an account with which to log in. |
-e | Disables command editing and history support, if it was compiled into the ftp executable. Otherwise, does nothing. |
-g | Disables file name globbing. |
-v | Verbose option forces ftp to show all responses from the remote server, and report on data transfer statistics. |
-d | Enables debugging. |
The client host and an optional port number with which ftp is to communicate may be specified on the command line. If this is done, ftp immediately attempts to establish a connection to an FTP server on that host; otherwise, ftp enters its command interpreter and await instructions from the user. When ftp is awaiting commands from the user, the prompt ‘ftp>’ is provided to the user. The following commands are recognized by ftp:
Command arguments which have embedded spaces may be quoted with quote («) marks.
Aborting a file transfer
To abort a file transfer, use the terminal interrupt key (usually Ctrl-C). Sending transfers are immediately halted. Receiving transfers are halted by sending a ftp protocol ABOR command to the remote server, and discarding any further data received. The speed at which this is accomplished depends upon the remote server’s support for ABOR processing. If the remote server does not support the ABOR command, an ‘ftp>’ prompt does not appear until the remote server has completed sending the requested file.
The terminal interrupt key sequence is ignored when ftp has completed any local processing and is awaiting a reply from the remote server. A long delay in this mode may result from the ABOR processing described above, or from unexpected behavior by the remote server, including violations of the ftp protocol. If the delay results from unexpected remote server behavior, the local ftp program must be killed manually.
File naming conventions
Files specified as arguments to ftp commands are processed according to the following rules:
1. If the file name ‘—’ is specified, the stdin (for reading) or stdout (for writing) is used.
2. If the first character of the file name is ‘|’, the remainder of the argument is interpreted as a shell command. ftp then forks a shell, using popen with the argument supplied, and reads (writes) from the stdout (stdin). If the shell command includes spaces, the argument must be quoted; (e.g., «» ls -lt»«). A particularly useful example of this mechanism is «dir more«.
3. Failing the above checks, if «globbing» is enabled, local file names are expanded according to the rules used in the csh; c.f. the glob command. If the ftp command expects a single local file (e.g., put), only the first file name generated by the «globbing» operation is used.
4. For mget commands and get commands with unspecified local file names, the local file name is the remote file name, which may be altered by a case, ntrans, or nmap setting. The resulting file name may then be altered if runique is on.
5. For mput commands and put commands with unspecified remote file names, the remote file name is the local file name, which may be altered by a ntrans or nmap setting. The resulting file name may then be altered by the remote server if sunique is on.
File transfer parameters
The FTP specification specifies many parameters which may affect a file transfer. The type may be one of «ascii«, «image» (binary), «ebcdic», and «local byte size» (for PDP-10’s and PDP-20’s mostly). ftp supports the ascii and image types of file transfer, plus local byte size 8 for tenex mode transfers.
ftp supports only the default values for the remaining file transfer parameters: mode, form, and struct.
Environment
The ftp command makes use of the following environment variables:
HOME | The default location of a .netrc file, if one exists. |
SHELL | The default shell. |
Examples
ftp exampleftp.computerhope.com
The command above instructs ftp to attempt a connection to exampleftp.computerhope.com. Below is an example of what would be seen:
Connecting to exampleftp.computerhope.com. exampleftp.computerhope.com FTP server ready. Name: yourusername Password:
If your username and password are valid and entered correctly, you are successfully logged in:
Remote system type is UNIX. Using ASCII mode to transfer files. ftp>
Once at the ftp> prompt, you are placed in the default directory for the user you used to log in. The first thing you’d probably want to do is see what directory that is. To see the present working directory, use the pwd command like in Linux:
257 "/ftpdefaultdir" is current directory.
The number 257 is a numerical code. All FTP messages have a code number associated with them, and for technical reasons they are included with the messages from the server. The server lets you know you’re in the /ftpdefaultdir directory. Let’s see what files are in there, using the ls command:
This produces a file listing, like in Linux. You can change remote directories with cd. To change what directory you’re using on your local computer, you can use lcd for «local change directory.» Let’s say you want to get a file from the server named awesome.jpg, and download it to your local directory /home/myuser/images:
ftp> lcd /home/myuser/images
Local directory now /home/myuser/images
local: awesome.jpg remote: awesome.jpg 200 PORT command successful. 150 Opening ASCII mode data connection for awesome.jpg (352271 bytes).
Oops! That’s not quite right. JPEG (Joint Photographic Experts Group) images are binary files, not ASCII (text) files.
FTP supports two different types of file transfers, ASCII and binary. At login, the server told us it was currently in ASCII mode. Let’s change that to binary:
Using binary mode to transfer files.
bin is short for binary, and either command switches to binary mode. We can now do the same file transfer and the file comes through correctly.
Let’s switch to the remote directory all-images.
250-README for all-images 250- 250-This folder contains all the JPEG images for our project. 250- 250 CWD command successful.
This directory had a «README» message displayed by the FTP server every time you change it to your current directory. The server then lets you know the cd command was successful. Now let’s download every JPEG file using a wildcard. We can use the mget command, which allows us to get multiple files with one command:
ftp> mget *.jpg *.jpeg *.JPG *.JPEG
We now get all the jpeg files with the extensions JPG, JPEG, jpg, or jpeg.
If we have any files to upload to the server, we can use the commands put or mput to upload them. When we’re done, we can logout using the exit command.
Related commands
scp — Copy files securely over a network connection.
sftp — Conduct an interactive FTP session over a secure network connection.
How to list directory content of remote FTP, recursively
After downloading files from a remote UNIX FTP server, you want to verify that you have downloaded all the files correctly. Minimal you will get information similar to «dir /s» command in Windows command prompt. The FTP client runs on Windows.
5 Answers 5
Sadly this was written for Unix/Linux users :/
Personally, I would install CYGWIN just to get Linux binaries of LFTP/RSYNC to work on windows, as there appears not to be anything that competes with it.
As @zadok.myopenid.com mentioned rsync, this appears to be a windows build for it using CYGWIN ( if you manage to be able to get ssh access to the box eventually )
Rsync is handy in that it will compare everything with check sums, and optimally transfer partial change blocks.
http://lftp.yar.ru/ is my favorite exploration tool for this.
It can do almost everything bash can do, albeit remotely.
$ lftp mirror.3fl.net.au lftp mirror.3fl.net.au:~> ls drwxr-xr-x 14 root root 4096 Nov 27 2007 games drwx------ 2 root root 16384 Apr 13 2006 lost+found drwxr-xr-x 15 mirror mirror 4096 Jul 15 05:20 pub lftp mirror.3fl.net.au:/> cd games/misc lftp mirror.3fl.net.au:/games/misc>find ./ ./dreamchess/ ./dreamchess/full_game/ ./dreamchess/full_game/dreamchess-0.2.0-win32.exe ./frets_on_fire/ ./frets_on_fire/full_game/ ./frets_on_fire/full_game/FretsOnFire-1.2.451-macosx.zip ./frets_on_fire/full_game/FretsOnFire-1.2.512-win32.zip ./frets_on_fire/full_game/FretsOnFire_ghc_mod.zip ./gametap_setup.exe . lftp mirror.3fl.net.au:/games/misc> du gametap_setup.exe 32442 gametap_setup.exe lftp mirror.3fl.net.au:/games/misc> du -sh gametap_setup.exe 32M gametap_setup.exe lftp mirror.3fl.net.au:/games/misc>