Linux – Connecting to FTP via the Linux command line

fedoraftplinuxunix

I need to upload files via FTP from the command line. I have this information: a URL, a username, a password, a port, and the fact that I am supposed to use passive mode.

How do I upload a file given this information?

Note that I am having to do this from a script, so I need to be able to enter this information automatically.

Best Answer

There's many CLI (command line) clients out there. Most common is simply ftp. You've got <host>, <port>, <username>, <pass> and "passive mode". Using ftp you should do:

ftp -p <host> <port>

-p switch means "use passive mode". Then you'll be asked about your username and password. After successful login (server let you know about that), you are able to give some commands. Type help and press "enter" to get list of commands available. You can use e.g. cd, ls, mkdir ftp commands to change working directory (on the server), list its contents and create a new directory. If before running ftp you were in the same directory as you files you want to send, you can use put or mput command to start actual transfer. First command sends one file, second multiple files using globbing (e.g. mput *pdf will send all pdf files in current directory). To get simple help about command you can use help <command> from within ftp app. I'd say that's enough for starters. For the rest use man ftp or info ftp. To end ftp session type bye. There are other ways to do that but I think this one is just elegant :).

As for the other clients, some interesting choices were pointed here, but I personally use lftp. It's just solid, good, flexible and easy to use ftp client. If you prefer more visual approach while still being under command line, you can go for mc or "Midnight Command". It's general application file manager utilizing Norton Commander paradigm, but can be also used to access ftp servers.

Related Question