Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
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.... –  SvW Mar 23 '12 at 11:37
add comment

3 Answers

up vote 3 down vote accepted

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).

share|improve this answer
    
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
add comment

lftp?

$ 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

share|improve this answer
add comment

Install ncftp and use the utitilies ncftpput and ncftpget.

share|improve this answer
    
Huh. For some reason, I had thought ncftp had been deprecated in favor of lftp. –  cjc Mar 23 '12 at 12:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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