Run FTP session from bash script

Posted by Adam Salkin on Server Fault See other posts from Server Fault or by Adam Salkin
Published on 2010-05-03T19:38:50Z Indexed on 2010/05/03 19:48 UTC
Read the original article Hit count: 481

Filed under:
|
|

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 username password

And I then did this from the prompt: adam$ ftp my.ftpsite.com < ftp-dummy

This does not work - I don't see the normal welcome message and the output is: Password:Name (my.ftpsite.com:adam) :

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

If I redirect the output to a testfile, the testfile shows: Name (my.ftpsite.com:adam): ?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 my.ftpsite.com

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. Thanks, Adam

© Server Fault or respective owner

Related posts about bash

Related posts about redirection