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". Usingftp
you should do:-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. Typehelp
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 runningftp
you were in the same directory as you files you want to send, you can useput
ormput
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 usehelp <command>
from withinftp
app. I'd say that's enough for starters. For the rest useman ftp
orinfo ftp
. To end ftp session typebye
. 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 formc
or "Midnight Command". It's general application file manager utilizing Norton Commander paradigm, but can be also used to access ftp servers.