- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- FTP script help
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2005 10:07 AM
02-10-2005 10:07 AM
Please find below the FTP script which I have written:
inp=ftp.config
file=abc
file1=def
for serv in `cat $inp`
do
echo $serv
echo "Trying to connect to $serv" > /tmp/ftp_log.${serv}
ftp -i -n <<-EOF >> /tmp/ftp_log.${serv}
open $serv
user anonymous
as
cd /tmp
prom
mget $file
quit
EOF
STAT=$?
echo $STAT
if [ ${STAT} = "0" ]; then
echo "FTP SUccessful to the server $serv" >> /tmp/ftp_log.${serv}
else
echo "There were some problems in connecting to $serv " >> /tmp/ftp_log.${serv}
fi
done
I am reading the server names from the input file and trying to connect to all the servers in the input file.
The script works good but the problem is that whenever a particular server is not reachable due to some network problem, the script times out. But my requirement is that the script should send a message to the log that it is not able to connect to a server and move on to the next server.
I have tried to use the FTP return status but it seems to be 0 even when the server is not reachable.
Is there a way in which I return an error to the FTP log file in case the file which I am trying to obtain is not availble in the server.
Also, I have to obtain '$file1' in case '$file' is not available. I don't know how to do this.
Please help.
Thanks,
Anand
Solved! Go to Solution.
- Tags:
- ftp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2005 10:27 AM
02-10-2005 10:27 AM
Solution#!/usr/bin/sh
inp=ftp.config
file=abc
dir=/tmp
USER=anonymous
cat ${inp} | while read SERV
do
echo "Testing connection to ${SERV} \c"
ftpget.pl -h ${SERV} -l ${USER} -z
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
echo "Ok"
echo "Getting file ${file} \c"
ftpget.pl -h ${SERV} -l ${USER} -d ${dir} -B -t 3 ${file}
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
echo "Ok"
else
echo "Failed to get file ${file} from host ${SERV}; status ${STAT}" >&2
else
echo "Failed to connect to ${SERV}. Status ${STAT}" >&2
fi
done
Invoke as ftpget.pl -u for full usage. Once you start using Perl for FTP, you will never use the kludgy shell scripts again.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2005 10:42 AM
02-10-2005 10:42 AM
Re: FTP script help
must use shell script, you could ping the ftp server
before doing the ftp.
ping FTPSERVER -n 1 | grep -q "100% packet loss"
if [ $? -eq 0 ]
then
echo "FTP_SERVER unreachable"
else
.... your script here
fi
Ping will timeout much quicker than ftp.
- Biswajit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2005 12:30 PM
02-11-2005 12:30 PM
Re: FTP script help
I have used your solution. It works great.
But I have a question. Sometimes I am having to fetch file say abc_${value}_*.
I understand from ftpget.pl that I have to use "-L" option when I am trying to fetch files that match some pattern.
I tried using the following command
ftpget.pl -h ${SERV} -l {USER} -p ${PASS} -A -t 3 -L 'abc_${value}_*'
It returns only the name of the file like abc_1234_98918. But it does not fetch the file.
Can you please help.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2005 02:33 PM
02-11-2005 02:33 PM
Re: FTP script help
ftpget.pl -h remotehost -l user -p passwd -d /xxx/yyy file1 file2 file3
This will get file1, file2, and file3 from directory /xxx/yyy on the remotehost.