1752802 Members
5666 Online
108789 Solutions
New Discussion юеВ

Re: script

 
SOLVED
Go to solution
heaman1
Regular Advisor

script

I have a unix server and use ftp client to connect the ftp server that provided from remote server ( only ftp is allowed ) , in remote server there have many .txt and .doc files ( in pairs ) , can advise if I want to have a script to do that if the .doc exists then download the corresponding .txt , for example , if aaa.doc exists in remote server then download aaa.txt, if bbb.doc exists then download bbb.txt and so on , can advise how to do it ? thx


aaa.txt
aaa.doc
bbb.txt
bbb.doc
ccc.txt
ccc.doc
2 REPLIES 2
Richard Hepworth
Esteemed Contributor
Solution

Re: script

Hi Heaman,

This should work for you:

ftp -vin < /tmp/file.list
open SERVER
user USER PASSWD
cd /path_to_files
ls *.doc
bye
EOT

cat /tmp/file.list | grep "\.doc" | awk '{print $NF}' | sed s'/\.doc//' | while read FILE
do
ftp -vin <open SERVER
user USER PASSWD
cd /path_to_files
get ${FILE}.doc
get ${FILE}.txt
bye
EOT
done
heaman1
Regular Advisor

Re: script

10 pt.

Thanks a lot.