Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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"

or

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

share|improve this question
    
Wait, FTP is not for that! FTP stands for File Transfer Protocol. You need SSH. –  nickguletskii Sep 14 '11 at 18:30
    
when you need to drive some nails and all you have is an ironing board... you make do with what you have. I'm trying Telnet, but FTP works. Limited control of second system and what not... FTP echo works even if it's an "Ironing board". –  WernerCD Sep 14 '11 at 18:50
    
Well, it didn't work for me... nick@AccessDenied:~$ ftp ftp> echo "hi" ?Invalid command ftp> –  nickguletskii Sep 14 '11 at 18:53
1  
ftp doesn't have an echo command. lftp does, but it's purely local, so I don't see why you'd want to do that by itself.... –  poolie Sep 14 '11 at 20:12
    
@nickguletskii Yeah... I was trying to get an answer to what I was doing wrong (maybe I could have been more clear). Charles has the answer that works for me (in addition to a cli-php solution that I got on SO). –  WernerCD Sep 14 '11 at 21:04
show 3 more comments

3 Answers 3

up vote 5 down vote accepted

That really is more of a job for SSH (as others have pointed out), but if your determined to use ftp try lftp. It should be installed on your system already.

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 broken in most distributions. -e will keep you connected unless you issue a quit.

share|improve this answer
1  
Eeeeew... Plain text passwords... –  nickguletskii Sep 14 '11 at 19:02
    
-c does work fine for me on Ubuntu. –  poolie Sep 14 '11 at 20:11
    
You don't need to put the password on the command line: one good option is to put it in ~/.netrc and make sure sure that's mode 0600. FTP can negotiate non-plain-text passwords on the wire. –  poolie Sep 14 '11 at 20:13
    
That works! Awesome. Yes... it's not a "Good" solution, but my options are limited on the second machine so FTP, while ugly, works. –  WernerCD Sep 14 '11 at 21:03
add comment

You can't use FTP for executing commands remotely. It stands for File Transfer Protocol. What you actually need is SSH.

All you need to do is install the package ssh on both machines and then follow this guide to set up password-less logins.

And now how to call it:

ssh username@host echo "Hello World\!"

For example, this is me doing it to myself:

nick@AccessDenied:~$ ssh nick@localhost echo "Hello World\!"
Hello World!
share|improve this answer
    
second system doesn't have SSH. I've actually got something working in PHP via FTP_RAW, but I will see if I can't get this working at some point. –  WernerCD Sep 14 '11 at 20:57
add comment

I found this thread when I was searching for a way to have a single ftp command execute a file transfer from this machine to the ftp server. Here is how:

Create a file with the ftp commands in it: (call it 'ftpcommands.txt')

 open YourFtpServer.com
 user YourUserName YourPassword
 put localfilename remotefilename
 bye

Then run the ftp command and feed the file into it:

 ftp -n < ftpcommands.txt

The -n option keeps ftp from trying to log in automatically when it receives you 'open' command.

Hope THAT helps someone. I couldn't find anything online that was this solution, so I had to figure it out myself.

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