Ubuntu – How to execute FTP commands on one line

10.10command lineftppipe

This is what I'm doing when I log into a FTP:

ftp user:password@server
ftp: user:password@server: Unknown host
ftp> echo HELLO WORLD!
ftp> quit

I'd like to do a one-line FTP command…

ftp user:password@server -command "echo HELLO WORLD"


"echo HELLO WORLD" | ftp user:password@server 

Something similar… as part of a script I'm trying to create. Nothing is getting transferred, I just need to echo some instructions and this is the easiest way I've found to do it between two of my systems.

Best Answer

  • That really is more of a job for SSH (as others have pointed out), but if you're determined to use ftp, try lftp. It's freely available for all currently supported versions of Ubuntu. You can install it with the command sudo apt install lftp

    lftp -u username,password -e "your command;quit" ftp.site.com

    lftp documents a -c switch that runs the command and then quits, but it appears to be broken in most distributions. -e will keep you connected unless you issue a quit.