How to Copy Files and Directories To and From Another System in Solaris using 'ftp' Command

This section explains how you can transfer files between systems using the File Transfer Protocol (FTP). The ftp command allows you to copy files from one computer to another over a network.

Using the ftp Command

The ftp command uses standard FTP to transfer files between systems with similar or dissimilar operating systems. You use FTP to transfer files in the American Standard Code for Information Interchange (ASCII) mode or the binary mode. FTP does not use the .rhosts file for authentication purposes. Instead, it prompts you for a password that is linked to the user as whom you sign in. If you are using anonymous FTP, your password is usually a valid email address.

The syntax for the ftp command is:

ftp hostname

When you access a remote system using the ftp command, some file and directory access commands, such as the ls and cd commands, are available at the ftp> prompt. If the permissions allow you to view the contents of a directory, the ls command lists files in a directory. If you do not have access to a directory or file, FTP generates a “Permission denied” error. The cd command changes the current working directory on the remote system.

To end an ftp session, perform the bye command or the quit command at the ftp> prompt.

Introducing FTP Transfer Modes

The default mode for file transfer using an ftp connection is the binary mode in the Solaris 9 OS. In the Solaris 8 OS or earlier versions, you can use the bin command to set the FTP transfer mode to the binary mode. The binary mode enables you to transfer binary, image, or any non-text files. The default mode for an ftp connection in the Solaris 8 OS or earlier versions is the ASCII mode. You can use this mode to transfer plain files such as text files.

Transferring Files by Using ASCII Mode

The following example establishes an FTP connection from the host1 system to the host2 system, gets the feathers file from the user2 directory on host2, stores the feathers file in the user1 home directory on host1 and quits the ftp session.

$ ftp host2
Connected to host2.
220 host2 FP server ready.
Name (host2:user1): user2
331 Password required for user2.
Password: password
230 User user2 logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ascii
200 Type set to A.
ftp> lcd ~user1
Local directory now /export/home/user1
ftp> ls
200 PORT command successful.
150 Opening ASCII mode data connection for file list.
dante
dante_1
dir1
dir2
dir3
dir4
dir5
file.1
file.2
file.3
file1
file2
file3
file4
fruit
fruit2
practice
tutor.vi
( directory list truncated )
226 Transfer complete.
133 bytes received in 0.081 seconds (1.61 Kbytes/s)
ftp> get fruit
200 PORT command successful.
150 Opening ASCII mode data connection for fruit (57 bytes).
226 Transfer complete.
local: fruit remote: fruit
66 bytes received in 0.042 seconds (1.54 Kbytes/s)
ftp> bye
221-You have transferred 66 bytes in 1 files.
221-Total traffic for this session was 1326 bytes in 4 transfers.
221-Thank you for using the FTP service on host2.
221 Goodbye.
$

Transferring Multiple Files

You can use the mget command to transfer multiple files from the remote system to the current working directory on the local system. You can use the mput command to transfer multiple files from the local system to a directory on the remote system.

You can use the prompt command to switch interactive prompting on and off. The system is set up to prompt you by default. When prompting is on during multiple file transfers, the system prompts you to confirm the transfer of each file before completing the transfer. The following example shows how you can establish an ftp connection from the host1 system to the host2 system. The ftp connection enables you to transfer multiple files using the prompt command, the mget command, and the mput command.

$ ftp host2
Connected to host2.
220 host2 FTP server ready.
Name (host2:user2): user2
331 Password required for user2.
Password:
230 User user2 logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
200 PORT command successful.
150 Opening ASCII data connection for file list.
file.1
file1
file.2
file2
file.3
file3
file4
fruit
fruit2
( file list truncated )
226 Transfer complete
52 bytes received in 0.028 seconds (1.79 Kbytes/s)
ftp> prompt
Interactive mode off
ftp> mget file.1 file.2
200 PORT command successful.
150 Opening BINARY mode data connection for file.1 (0 bytes).
226 Transfer complete.
200 PORT command successful.
150 Opening BINARY mode data connection for file.2 (0 bytes).
226 Transfer complete.
ftp> mput file3 file4
200 PORT command successful.
150 Opening BINARY mode data connection for file3.
226 Transfer complete.
200 PORT command successful.
150 Opening BINARY mode data connection for file4.
226 Transfer complete.
ftp> prompt
Interactive mode on.
ftp> mget file.1 file.2
mget file.1? y
200 PORT command successful.
150 Opening BINARY mode data connection for file.1 (0 bytes).
226 Transfer complete.
mget file.2? y
200 PORT command successful.
150 Opening BINARY mode data connection for file.2 (0 bytes).
226 Transfer complete.
ftp> bye
221-You have transferred 0 bytes in 8 files.
221-Total traffic for this session was 2654 bytes in 13 transfers.
221-Thank you for using the FTP service on host2.
221 Goodbye.
$

Transferring Files by Using Binary Mode

The following example shows how to transfer a binary file. In the Solaris 9 OS, the binary mode for file transfer is the default mode.

$ cd /tmp
$ ftp host2
Connected to host2.
220 host2 FTP server ready.
Name (host2:user2): user2
331 Password required for user2.
Password:
230 User user2 logged in.
Remote system type is UNIX.
ftp> get binary.file
200 PORT command successful.
150 Opening BINARY mode data connection for binary.file (19084 bytes).
226 Transfer complete.
local: binary.file remote: binary.file 19084 bytes received in 0.0044 seconds (4212064 Kbytes/s)
ftp> bye
221-You have transferred 19084 bytes in 1 files.
221-Total traffic for this session was 19507 bytes in 1 transfers.
221-Thank you for using the FTP service on host2. 221 Goodbye.
$