ftp ipaddress
bin
hash
cd path
get filename
quit
i want these line to be executed in a shell script only first line is executing after entering username and password the rest line are not executing and the control is stuck at ftp> prompt
ftp ipaddress
bin
hash
cd path
get filename
quit
i want these line to be executed in a shell script only first line is executing after entering username and password the rest line are not executing and the control is stuck at ftp> prompt
Once your script invokes the program ftp
, the shell loses control until the ftp program finishes. So you need to use some new technique. One way is with the program expect
, which you can get a hint about here: https://stackoverflow.com/a/12598169/4323 . Another way is to use a more "scriptable" FTP client, such as lftp
on Linux, which has specific features to enable the sort of scripted use you're going for.
Or you can use a shell "here" document:
#!/bin/bash
ftp -in <<EOS
user pswd
bin
hash
cd path
get filename
quit
EOS
The here document sends everything via the open program's stdin, just as if you typed it in at the command line. Note that ftp clients can be finicky and each one seems to have it's own set of gotchas, so some experimentation and use of man ftp
will likely be required.
Looks like this has come up before on Stackoverflow, you might want to read through how to ftp multiple file using shell script
IHTH