- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Script to test FTP functionality
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
06-15-2006 12:39 AM
06-15-2006 12:39 AM
We have around 400 servers here and I want to write a script to see where FTP is available and where it is not, on all servers. It is open on all in the inetd, but we are not sure about the firewall rules...and not having anything to do with the firewall, I need to find another course of action. So is there a way to test ftp functionality on all servers? Like with SSH, I just ssh to each server and run hostname. With ftp, I would have to telnet to port 21, but that is interactive and so is ftp'ing to a server. There is also where you ftp to a server and it doesn't open a connection but just hangs there until a CTRL-C is done...so I would need a timeout.
Thanks,
Solved! Go to Solution.
- Tags:
- ftp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2006 12:45 AM
06-15-2006 12:45 AM
Re: Script to test FTP functionality
Install nmap and scan port 21.
PCS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2006 12:49 AM
06-15-2006 12:49 AM
Re: Script to test FTP functionality
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2006 02:08 AM
06-15-2006 02:08 AM
Re: Script to test FTP functionality
I'm not sure that there's an easy way to accomplish this. What follows is one possible solution, but it requires remsh permission on each server (set in /etc/hosts.equiv).
Say s_list.text contains a list of the 400 server hostnames, one per line. If user@host1 can is authorized to remsh on each of these servers, then a script like the following might work:
#!/usr/bin/sh
for i in $(cat s_list.text)
do
echo "Result for host $i:" >> results.text
remsh $i ftp
done
exit 0
After the script is done, review results.text. Check out every line following "Result for host". If you see something like:
ftp:
Then
Name (
Login failed.
You know that
Good luck!
PCS
- Tags:
- remsh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2006 02:25 AM
06-15-2006 02:25 AM
Re: Script to test FTP functionality
ftp -in server << EOF
user username password
get /something
put /something_else
EOF
With EOF you don't worry about a timeout or control c.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2006 02:28 AM
06-15-2006 02:28 AM
SolutionHere's a potentially workable approach. The script needs embellishment. You will need to add a driver loop to query your hosts and to collect the results. A simple file of hostnames (or IP addresses) will do as input. A simple log of the output will suffice.
# cat .query21
#!/usr/bin/sh
typeset HOST=${1}
telnet ${HOST} 21 |&
sleep 3
read -p REPLY
read -p REPLY
print -p quit
ACTION=`echo ${REPLY}|cut -d" " -f1`
if [ "${ACTION}" != "Connected" ]; then
echo "${HOST} FAILED to connect"
else
echo "${HOST} reponded_ok!"
fi
exit 0
...Run as:
# ./query21 somehost
...The exact message ("Connected ...") returned, may vary and that may need some tweaking too.
You will see output like:
telnet: connect: A remote host refused an attempted connect operation.
/tmp/telnet[7]: print: 0403-039 No query process for pipe.
xxxxxxxx to connect
...for a failure; and:
xxxxxxxx reponded_ok!
...for success.
This offers you a direction, at least.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2006 02:35 AM
06-15-2006 02:35 AM
Re: Script to test FTP functionality
Assuming you have the list of hostnames in a file hosts.dat
The script is attached
Regards,
Ninad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2006 02:41 AM
06-15-2006 02:41 AM
Re: Script to test FTP functionality
The trick here is to give junk username and password so that ftp fails [ for server where it is able to connect thru ftp ]
If you cannot connect to a server it is also displayed.
Regards,
Ninad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2006 02:49 AM
06-15-2006 02:49 AM
Re: Script to test FTP functionality
#!/usr/bin/sh
typeset HOST=remhost
typeset USER=mickey
typeset PASSWD=topsecret
typeset -i TIMEOUT=20
typeset -i STAT=0
ftpget.pl -h ${HOST} -l ${USER} -p ${PASSWD} -s ${TIMEOUT} -z
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
echo "${HOST} Okay"
else
echo "FTP to ${HOST} failed; status ${STAT}" >&2
fi
exit ${STAT}
This will attempt to establish an ftp connect to the remote. It is not necessary to supply a password on the command line as that can be read from an optional .netrc file.
Invoke as ftpget.pl -u for full usage; this will also transfer your files with full error checking and optional repeat requests if a transfer fails.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2006 02:51 AM
06-15-2006 02:51 AM
Re: Script to test FTP functionality
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2006 03:07 AM
06-15-2006 03:07 AM
Re: Script to test FTP functionality
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2006 03:12 AM
06-15-2006 03:12 AM
Re: Script to test FTP functionality
nmap was made for this sort of thing.
Get the depot here:
http://hpux.connect.org.uk/hppd/hpux/Networking/Admin/nmap-3.93/
Then:
nmap -p 21
PCS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2006 03:15 AM
06-15-2006 03:15 AM
Re: Script to test FTP functionality
...and the script I suggested does *not* attempt to login to a server. It merely queries the connection result.
I'm sure that with 400 servers the accounts and passwords are not all the same :-))
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2006 03:24 AM
06-15-2006 03:24 AM
Re: Script to test FTP functionality
S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2006 03:26 AM
06-15-2006 03:26 AM
Re: Script to test FTP functionality
Did you try the script I have posted. It uses junk user and password in the script so you need not mention and reveal actual passwords also script automatically checks conenctions for each host and you do not need to enter anything.
Regards,
Ninad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2006 03:26 AM
06-15-2006 03:26 AM
Re: Script to test FTP functionality
ftpput.pl -h goodhost -s 15 -z 2>/dev/null
STAT=${?}
echo "${STAT}" # this will be 5; meaning I could connect but the login failed
ftpput.pl -h badhost -s 15 -z 2>/dev/null
STAT=${?}
echo "${STAT}" # this will not be 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2006 05:33 AM
06-15-2006 05:33 AM