Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to write a BASH script to test if an FTP site that I own is running. I therefore want the bash script to connect to the FTP site, log in with a dummy account and redirect the output to a file that I can then grep to confirm that the login succeeded.

(I know that putting user/pass in a file is not recommended, but this dummy account is chrooted to one empty directory and can't escape to the shell, and in any case I'm the only user who can login to a shell prompt.)

I'm using the BASH shell on Ubuntu.

I created a file called "ftp-dummy" which looks like this


And I then did this from the prompt:

adam$  ftp  < ftp-dummy

This does not work - I don't see the normal welcome message and the output is:

Password:Name ( :

I tried removing the space between the < and the filename - same result.

If I redirect the output to a testfile, the testfile shows:

Name ( ?Invalid command

And I still get a Password prompt on STDOUT

I also tried using echo and get the same result:

echo -e "username \npassword \n" | ftp 

I don't see why I'm not seeing the normal welcome message or why the input is not being read from the file. Any help would be much appreciated.


share|improve this question
The file "ftp-dummy" does have the Username and Password on two separate lines - this is what I wrote but it changed when I completed posting this question. – Adam Salkin May 3 '10 at 19:43

use scriptable ftp client like lftp.

you use it like this:

lftp -u login,pass -e "get file.txt;exit "

or even simpler - use wget:

wget -O file
share|improve this answer
Thank you, this worked. I also got it working using a HERE document: ftp <<TheEnd username password ls quit TheEnd And thanks to Dennis for editing my question to show things correctly. – Adam Salkin May 3 '10 at 20:51

I've encountered issues redirecting STDIN with UNIX ftp clients before. While I'll often try to work through them, I've found expect to be better suited in many situations.

You might also take a look at nagios-plugins check_ftp, as you could potentially pull that out and use it for your purposes. Often, there's little need to reinvent the wheel.

To specifically answer your question, FTP's netrc file will provide the authentication details on your behalf.

share|improve this answer

There is a flag on ftp that you can use to stop the automatic password request when you send the user command.

man ftp

ftp -n

Then you can pipe your commands (including user and pass) to ftp.

share|improve this answer

Your Answer


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.