1827953 Members
3472 Online
109973 Solutions
New Discussion

ftp script

 
SOLVED
Go to solution
vas  bolpali
Advisor

ftp script


I have 3 files on FTP Server.
abc123.main
abc123.data
abc123.end

i will get the file name(abc123) from another file(/tmp/filenames)

$cat /tmp/filenames
abc123

now my requirement is
I need to check , whether 'abc123.end' exists on the FTP server(111.222.49.55)
if exists , then I need to grab the 2 other files(abc123.main,abc123.data)

----------
thanks in advance.
keeping you ahead of the learning curve
3 REPLIES 3
harry d brown jr
Honored Contributor

Re: ftp script

Something like this:
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x1464c1c4ceddd61190050090279cd0f9,00.html

live free or die
harry
Live Free or Die
Simon Hargrave
Honored Contributor
Solution

Re: ftp script

Do it with 2 FTP's (per fileset), and test for the file inbetween. eg: -


---

SERVER=ftpserver1
USER=ftpuser
PASS=ftppass

for FILE in `cat /tmp/filenames`
do
ftp -n $SERVER < user $USER $PASS
get ${FILE}.end
bye
EOF

if [ -f ${FILE}.end ]; then
ftp -n $SERVER < user $USER $PASS
get ${FILE}.main
get ${FILE}.data
bye
EOF
fi
done

---
F. X. de Montgolfier
Valued Contributor

Re: ftp script

Simon's script is almost perfect, but I'd add two very minor modifications:
- ftp -in instead of ftp -n to disable prompting, and
- choose the correct transfert mode... chnage TMODE to ascii or binary depending of the appropriate mode...

no need to give me points on what is, in fact, only nitpicking ;-)

SERVER=ftpserver1
USER=ftpuser
PASS=ftppass
TMODE=

for FILE in `cat /tmp/filenames`
do
ftp -in $SERVER <user $USER $PASS
$TMODE
get ${FILE}.end
bye
EOF

if [ -f ${FILE}.end ]; then
ftp -in $SERVER <user $USER $PASS
$TMODE
get ${FILE}.main
get ${FILE}.data
bye
EOF
fi
done

Cheers,

FiX