2024-01-01
The fundamental step is establishing a connection. The basic syntax is simple:
ftp <ftp_server_address>Replace <ftp_server_address> with the actual IP address or domain name of the FTP server. For instance, to connect to ftp.example.com:
ftp ftp.example.comYou’ll likely be prompted for your username and password.
Once connected, you can navigate the remote server’s file system using commands similar to those found in your local shell.
pwd (print working directory): Displays your current directory on the remote server.pwdls (list directory contents): Lists the files and directories in your current remote directory. The -l option provides a detailed listing.ls
ls -lcd <directory> (change directory): Changes your current directory on the remote server. To move up one level, use cd ...cd /pub/documents
cd ..The core functionality of ftp lies in its file transfer capabilities.
get <remote_file> <local_file> (download): Downloads a file from the remote server to your local system. If you omit <local_file>, the file will be downloaded with the same name.get report.pdf
get /pub/images/logo.png mylogo.pngput <local_file> <remote_file> (upload): Uploads a file from your local system to the remote server. Again, omitting <remote_file> uses the local filename.put mydocument.txt
put myimage.jpg /pub/images/newimage.jpgmget <remote_file1> <remote_file2> ... (download multiple): Downloads multiple files at once. Use wildcards for efficient selection.mget *.txtmput <local_file1> <local_file2> ... (upload multiple): Uploads multiple files simultaneously. Wildcards are also supported here.mput *.jpgSome firewalls or network configurations require using passive mode for successful FTP connections. Enable passive mode with:
passiveAfter this command, subsequent file transfers will utilize the passive mode. To return to active mode, use:
activeWhen finished, disconnect from the FTP server using:
byeThe ftp command offers many more options for fine-grained control over transfers, including resuming interrupted transfers, setting transfer speeds, and more. Refer to the man ftp page for a complete list of available options and commands. Experimentation and the manual page are your best allies in mastering this powerful tool. Remember to always be mindful of security best practices when using FTP, particularly when handling sensitive data.