Suggestion on coding this kind of requirement
Hi,
I would like to ask suggestion from you guys on how can I achieve this requirement. I would like to connect a a public ftp server, I already have the code to connect to it via script however, my requirement is to download only files that are listed on a txt file. I could do a command such as mget file1 file2 file3...etc. But how do I feed to the ftp program the list of file names that it should download. Here is the snippet of my code. TIA. #!/usr/bin/bash ftp -i -n << "END" open publicserver.com user anonymous 123 bin cd loc1 mget file1.asc file2.asc bye END echo "ftp complete" |
Add this cmd
$file_list=`cat file_list.txt` before the ftp stuff then amend the mget mget $file_list |
can i output an ls command such that it would fit the requirements of the mget of ftp? For example, ls /dir > file_list.txt, where in the output would be file1 file2 file3?
|
If you just want the entire dir, use
mget * or mget *.* |
nope, I am not going to get all the files, only the files that are included on the list.
|
That's what my 1st suggestion was for ...
|
have already manually edited the file. thanks for your suggestion. :)
|
Quote:
You could also do $files_list=`ls /dir` which amounts to the same thing. |
Something like that maybe:
Code:
#!/usr/bin/bash Yves. |
Hi,
When I try to run the script, I get a $file_list.txt: no such file or directory error. I think ftp can not translate the value of my cat command... |
That's where sometimes, the functionality of some commands doesn't let the programmer have control of.
Here's a simple in Perl too where there's more "control" ... Code:
use Net::FTP; |
Thanks for suggesting perl but is there another way for bash shell to do it?
|
Quote:
ftp is not evaluating $(...) constructs, bash is. But you have to write it exactly so, with '$(' at the start of the command, and ')' at the end. Yves. |
this my code:
#!/usr/bin/bash ftp -i -n << "END" open www.publicserver.com user anonymous 123 bin cd public mget $(cat /export/home/noc/vsftpd-2.0.4/bin/files1.txt) bye END echo "ftp complete" When I try to run it, I get this error: "$(cat: No such file or directory. /export/home/noc/vsftpd-2.0.4/bin/files1.lst): No such file or directory. can't find list of remote files, oops ftp complete" I agree that bash can translate variables with $ but on my script, ftp was invoked on bash and the way I see it, ftp is the one evaluating the variables enclosed on the << END portion of the program. |
OK I get it.
It's because you put quotes around END. Try without the quotes, like this: ftp -i -n <<END Yves. |
All times are GMT -5. The time now is 04:51 PM. |