How to Use FTP Through the Command Line in Mac OS X
FTP (File Transfer Protocol) is a way for computers to transfer files over an IP network. In Mac OS X Server, FTP is started from the command-line interface (CLI). In this article how-to, we’ll show you how to put the command line to good use by connecting to an FTP server.
- Connecting to an FTP Server
- To establish a connection with an FTP server, you’ll need to know your username and password, in addition to the server you’re connecting to (i.e. “com”).
- To open a connection in Terminal (located in /Applications/Utilities), type the following command, replacing the underlined portions with your server:
ftp YourServerHere. com
- After a few seconds, you’ll be prompted for your username and password by the server. Type those in, pressing Enter after entering each piece of information.
- Browsing Around
- Then you’ve gotten the “ftp>” line displayed, you can issue the FTP server a command.
- To list the files in a particular folder, type ls (that’s LS in lower-case), then press Enter.
- Files will have a dash (-) as the first character in the leftmost column and folders will have a d listed ("d" stands for directory).
- To navigate into a folder, type cd (as in “change directory”), followed by the directory name you want to change to. Then, press Enter to send the command to the server. So, if I wanted to list the files in my Documents Folder, I would first type in:
ftp> cd Documents
ftp> ls
- The files and folders in the Documents folder would then be listed.
- Uploading or Downloading from the Server
- Download a file is easy. First, navigate to the folder containing the file you want to download. Next, type in the following command, specifying the file you want to download in place of the underlined text:
get file_name_here.pdf
- Any files you download will appear in the Home directory of the currently logged in user on your Mac.
- Uploading a file to the server is just as easy. Instead of “get”, you’re going to use “put” then the filename of the file on your local machine. So, if you had a file on my Desktop called Downloads.rtf that you wanted to put on the server in our Documents folder, you would type the following command:
put ~/Desktop/Download.rtf ~/Documents/Download.rtf
- The first statement after the put command is the location on your local machine containing the file, in this case, ~/Desktop/Download.rtf; the second statement is the location on the server where the file should reside after upload, in this case ~/Documents/Download.rtf.
- List of Commands
As you can see, the command line FTP client can be great when you’re in a pinch and need to do some basic FTP server work. Just to recap, here’s a list of the basic commands that you can use with the FTP client built into Mac OS X.
- ftp - Starts the FTP command line interface session
- open - Start your connection to another computer
- ls - Get a list of files in the current directory
- cd - Change directory
- put filename - Upload a file to the server
- get filename - Download a file from the server
- mput filename - Put multiple files on the server
- mget filename - Get multiple files on the server
- quit - Ends your ftp session