Operating System - HP-UX
1830931 Members
2380 Online
110017 Solutions
New Discussion

Script to connect FTP Servers

 
SOLVED
Go to solution
panchpan
Regular Advisor

Script to connect FTP Servers

Hello,
I have a list of > 50 FTP Servers. Can you please tell me script to test if ftp works for each server. I want to see the result as connecting or not connecting only. No login password verification required.

Thank you!
5 REPLIES 5
gstonian
Trusted Contributor
Solution

Re: Script to connect FTP Servers

Not exactly what you are after but I hope you can crib this to do what you want. Use a input list of all the servers and wrap it round the ftp & just loop. You don't need the transfer part of course but as I don't have time to write the actual script I hope this one helps.

SRCFILE=$1
DSTFILE=$2
IPADDR=$3
USERID=$4
PASSWORD=$5
SRCDIR=$6
DSTTYPE=$7


#depending on what parameters are passed in to the relavant copy

# FTP Files from Current Server to IPADD

(
ftp -vin <open $IPADDR
quote USER $USRID
quote PASS $PASSWORD
put $SRCDIR/$SRCFILE $DSTFILE
quit
END_SCRIPT
) | grep "226 Transfer complete." > /tmp/ftp$SRCFILE

if [[ -s /tmp/ftp$SRCFILE ]]
then
echo "FTP Completed Sucessfully"
James R. Ferguson
Acclaimed Contributor

Re: Script to connect FTP Servers

Hi:

You could use this:

# cat .connectme
#!/usr/bin/perl
use strict;
use warnings;
use Net::FTP;

for my $host (@ARGV) {
Net::FTP->new($host) or die "Can't connect to $host\n";
}
1;

...run the script passing as many hostnames as you wish. For example;

# ./connectme host1 host2 host3

If a FTP connection can be made, nothing is returned, otherwise a suitable message is written to STDERR.

Regards!

...JRF...
Peter Godron
Honored Contributor

Re: Script to connect FTP Servers

Hi,
how about:

#!/usr/bin/sh
while read host
do
echo "bye" |ftp -n $host
if [ $? ]
then
echo "Not Connecting [ $host ]"
else
echo "Connecting [ $host ]"
fi
done < file_of_ips
Peter Godron
Honored Contributor

Re: Script to connect FTP Servers

Hi,
could you please complete the thread by awarding points to helpful answers and summarising the solution for you.

This will help resolution of similar problems in the future.

Please read:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33 on how to reward any useful answers given to your questions.
panchpan
Regular Advisor

Re: Script to connect FTP Servers

Thank you all!