FTP on the command line

February 16th, 2009. Tagged: tools

Since I switched to Mac I need to learn a bunch of stuff I was taking for granted for years. Recently I needed to upload a bigger file or two to my server and scp is not the tool for the job. So instead of starting a hunt for a decent free FTP client, I tried the good old command line.

Turns out it's much easier to FTP files from the command line than I would think.

Connecting to the server

$ ftp phpied.com
Connected to phpied.com.
220---------- Welcome to Pure-FTPd [TLS] ----------
220-You are user number 1 of 50 allowed.
220-Local time is now 02:17. Server port: 21.
220-IPv6 connections are also welcome on this server.
220 You will be disconnected after 15 minutes of inactivity.
Name (phpied.com:stoyan): myusername
331 User myusername OK. Password required
Password:

After supplying your credentials you're in and you have an inviting ftp> prompt:

230 OK. Current restricted directory is /
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>

So what do you do here? You can list available commands with
ftp> help

You can navigate with cd (good old "change directory")

ftp> cd www/phpied.com/files
250 OK. Current directory is /www/phpied.com/files

You can list the contents of a remote directory with ls or dir.

And finally you can copy files from your desktop to the remote machine. You don't copy files, you PUT them. You're rewarded with a nice progress indicator.

ftp> put src.zip 
local: src.zip remote: src.zip
229 Entering Extended Passive Mode (|||59237|)
150 Opening BINARY mode data connection for src.zip
 10% |***                                  |   511 KB   64.00 KB/s    01:09 ETA

later...

ftp> put src.zip 
local: src.zip remote: src.zip
229 Entering Extended Passive Mode (|||59237|)
150 Opening BINARY mode data connection for src.zip
 93% |**********************************   |  4607 KB   45.62 KB/s    00:07 ETA

finally...

ftp> put src.zip 
local: src.zip remote: src.zip
229 Entering Extended Passive Mode (|||59237|)
150 Opening BINARY mode data connection for src.zip
100% |*************************************|  4938 KB   44.73 KB/s    00:00 ETA
226 Transfer complete.
5056569 bytes sent in 01:53 (43.55 KB/s)

And then, bye-bye:

ftp> quit
221 Goodbye.

Comments? Find me on BlueSky, Mastodon, LinkedIn, Threads, Twitter