I want to automate sending of a file through FTP using command line (on Linux). By this I mean that I want to send a file straight from the command line, without any interactive mode. I want to pass all parameters from the command line (it is on a local network for private purposes, so having password on the command line is fine for me). I know what file I want to send, and where I want to store it. My google-fu has failed me so far, because all guides concerning "command line ftp" are actually entering the interactive text interface, which is not what I want.

So how do I send a file through FTP if I do not want to enter the interactive mode and want to pass all parameters on command line?

  • What OS? What FTP program? – Tim Brigham Mar 23 '12 at 11:34
  • @TimBrigham: The linux tag indicates the OS, and since it's easy to install additional tools on any Linux.... – Sven Mar 23 '12 at 11:37

If possible, install ncftp and use ncftpput and ncftpget commands for scripting uploading and downloading files.

lftp has also -c (reads FTP commands from command line parameters) and -f (reads FTP commands from a text file) options which can help you automating your FTP sessions.

If you somehow truly have to use the archaic ftp command, you can use expect (or, autoexpect).

  • Thanks, ncftpput -u user -p pass host remote-dir local-file works great. – MiKy Mar 23 '12 at 11:40
  • Great. Have a nice weekend! :) – Janne Pikkarainen Mar 23 '12 at 11:41


$ yum info lftp
Loaded plugins: priorities, ps
Available Packages
Name        : lftp
Arch        : i686
Version     : 4.0.9
Release     : 1.el6
Size        : 735 k
Repo        : base
Summary     : A sophisticated file transfer program
URL         : http://lftp.yar.ru/
License     : GPLv3+
Description : LFTP is a sophisticated ftp/http file transfer program. Like bash, it has job
            : control and uses the readline library for input. It has bookmarks, built-in
            : mirroring, and can transfer several files in parallel. It is designed with
            : reliability in mind.

The man page is here: http://lftp.yar.ru/lftp-man.html


Install ncftp and use the utitilies ncftpput and ncftpget.

  • Huh. For some reason, I had thought ncftp had been deprecated in favor of lftp. – cjc Mar 23 '12 at 12:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.