Exchanging Files with Linux/Unix Hosts Using ftpSometimes you need to transfer files over the network between two computer systems. The command traditionally used to transfer files between two Linux or Unix systems is ftp, which stands for file transfer protocol. As with remote logins, you can use an ftp client only with systems that allow incoming ftp connections with an ftp server. If you find, while following the instructions in this section, that your connect attempts fail with an error message, it is likely that the remote system does not accept file transfer protocol connections. Starting ftp and Logging InFull use of the ftp command also requires that you connect to a remote system and then log in with an account and password; you thus have to be known on the remote system before you can connect via ftp. To connect to a remote system with ftp, enter the ftp command at the command prompt supplying the domain name of the system you want to connect to as an argument. You are then prompted for your account and password before being delivered to the file transfer prompt. In this example, a connection is made with a system having the hostname archive3.mycompany.com: [you@workstation20 ~]$ ftp archive3.mycompany.com Connected to archive3.mycompany.com (10.6.2.2). 220 archive3 FTP server (Version wu-2.6.1-20) ready. Name (10.6.2.2:you): jackhenry 331 Password required for jackhenry. Password: 230-Please read the file README.TXT 230- it was last modified on Fri Aug 2 15:43:13 2002 230 User jackhenry logged in. Remote system type is UNIX. Using binary mode to transfer files. ftp> After you log in, you are sitting at the ftp> TRansfer prompt, from which ftp commands can be entered to list, upload, or download files.
Navigating an ftp LoginYou will find that being logged in to a remote system via ftp is not unlike sitting at a remote system's command prompt in some ways. As is the case with a "normal" command prompt, you can display a present working directory with pwd. You can list files and directories with ls, and you can use the cd command to navigate to other directories that you have permission to visit. There is, however, one major difference between using the ftp screen and a remote system command prompt. When logged in to ftp, you have not one present working directory, but twothe one on the local system and the one on the remote system. These dual working directories facilitate the transfer of files between the two systems; files are normally copied between the local and remote present working directories. The process of transferring files therefore involves the following steps (see the commands to implement them in Table 24.1 and a sample session in the next section):
Some of the more fundamental commands that you can use in an ftp session are shown in Table 24.1. Because this process and command set can seem much more complicated than it actually is, you may find a sample session helpful for illustration purposes. Working Through a Sample ftp SessionSuppose you have just successfully logged in to your account on a remote ftp server. In most cases, your local present working directory is the same present working directory you were using when you started ftp. At the same time, your remote present working directory often begins as /home/youraccount on the remote system (in this case, /home/jackhenry). In this session, the goal is to copy files as follows:
Because the first source file is located in the home directory of the local system and is to be copied to your home directory on the remote system, no changes in the present working directory need to be made. Simply use the put command to copy the first file: ftp> put basicfile.txt local: basicfile.txt remote: basicfile.txt 227 Entering Passive Mode (10,6,2,2,225,31) 150 Opening BINARY mode data connection for basicfile.txt. 226 Transfer complete. 115 bytes sent in 0.00075 secs (1.5e+02 Kbytes/sec) ftp> The first file has now been copied from the local system to the remote system. The next file resides in the textfiles directory on the local system and will be put into the documents directory on the remote system, so some changes to present working directories are required: ftp> lcd textfiles Local directory now /home/you/textfiles ftp> !pwd /home/you/textfiles ftp> cd documents 250 CWD command successful. ftp> pwd 257 "/home/jackhenry/documents" is current directory. ftp> Now that both present working directories are correct (as has been verified with !pwd and pwd), you can use put to copy the file: ftp> put mypaper.tex local: mypaper.tex remote: mypaper.tex 227 Entering Passive Mode (10,6,2,2,120,95) 150 Opening BINARY mode data connection for mypaper.tex. 226 Transfer complete. 101842 bytes sent in 0.014 secs (7.1e+03 Kbytes/sec) ftp> Finally, you must retrieve a file called mypicture.gif from a remote directory and store it in the local home directory: ftp> lcd /home/you Local directory now /home/you ftp> !pwd /home/you ftp> cd ../images 250 CWD command successful. ftp> pwd 257 "/home/jackhenry/images" is current directory. ftp> get mypicture.gif 227 Entering Passive Mode (10,6,2,2,232,161) 150 Opening BINARY mode data connection for mypicture.gif (220376 bytes). 226 Transfer complete. 220376 bytes received in 0.179 secs (1.2e+03 Kbytes/sec) ftp> All the files in the list have now been transferred; you can close the connection: ftp> close 221-You have transferred 322333 bytes in 3 files. 221-Total traffic for this session was 323337 bytes in 3 transfers. 221 Thank you for using the FTP service on archive3. ftp> quit [you@workstation20 ~]$
|