LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   ftp commands in shell script (https://www.linuxquestions.org/questions/linux-newbie-8/ftp-commands-in-shell-script-728545/)

vinaytp 05-26-2009 04:43 AM

ftp commands in shell script
 
hi all........

ftp localhost
ls
quit

i am trying to run above script ...

when i try to run it will ask for passwd and it will login correctly...

but in ftp> prompt ls and quit is not executing ...can anyone help me please....

Thanks in advance

colucix 05-26-2009 04:51 AM

You have to pass ftp commands as standard input to the ftp statement. Use a "here document" like in the following example:
Code:

ftp -ni host << EOF > /dev/null
user username password
ls
bye
EOF

Note that the closing EOF must be at the beginning of the line (no leading spaces or tabs) otherwise it is not interpreted from the shell and the standard input is not terminated. Also the user command let you avoid to interactively type username and password. A downside is that you have to write the password in clear text in a script and other people may read (and use) it.

schneidz 05-26-2009 08:32 AM

may i suggest scp

Poetics 05-26-2009 10:59 AM

Quote:

Originally Posted by schneidz (Post 3553155)
may i suggest scp

For doing a simple `ls`, I think `ssh` may be more useful, but that's just my $0.02 -- there are many ways to arrive at the same goal!


All times are GMT -5. The time now is 03:42 PM.