Operating System - HP-UX
1827876 Members
1259 Online
109969 Solutions
New Discussion

Where can I find an FTP script to automate

 
SOLVED
Go to solution
John Jimenez_2
Occasional Advisor

Where can I find an FTP script to automate

I am in a situation where many users FTP into our HP/UX 10.20 K570 for downloads. I am worried and have security issues with this access, but realize that these users need access to data. I on the other hand do not want to add this task on to my job description.
I have just set up an FTP server on an NT 4.0 server, and I can now manually FTP from my HP to the NT Server. I have written simple scripts before, but am in no way an expert. I tried to write a script that will FTP about 180 files onto the NT FTP server. It connects to the server, but does not go further.
The Script Connected to 10.xxx.xxx.xxx.
220 Serv-U FTP Server v3.1 for WinSock ready...
Name (10.xxx.xxx.xxx:root):
Where can I find a similar script that I can use as a templete?
Do not worry about where you are at in your life right now, as long as you moved a little in the right direction from yesterday to today, and am moving in the right direction today for tomorrow.
3 REPLIES 3
S.K. Chan
Honored Contributor
Solution

Re: Where can I find an FTP script to automate

Mike Hassell
Respected Contributor

Re: Where can I find an FTP script to automate

John,

Please see the attached script for an example of a script that will accomplish what you're after. Basically you can call this script from another script and pass it the following information:


Usage: ftp_batch hostname userid passwd get|put src_file dest_file

So if you have mutiple files that you need to transfer you can either copy the script into your existing script or just loop with the list of files to transfer and call this script each tiem in that loop. If you need more examples just reply back here, but this should help with the FTP portion.

In case the script doesn't attach properly, here is the full thing:
if [ $# -ne 6 ]
then
echo "Usage: ftp_batch hostname userid passwd get|put src_file dest_file"
exit 1
else
{
ftp -v -n <open $1
user $2 $3 0
$4 $5 $6
EOF
} |grep -e "226 Closing" -e "226 Transfer complete." -e "226 ASCII Transfer complete."> /dev/null
error_code=$?
if [ $error_code -eq 0 ]
then
echo "FTP: $4 $5 $6 on host $1 for $2"
else
echo "FTP error: $4 $5 $6 on host $1 for $2"
fi
exit $error_code
fi

Hope that helps.

-Mike


The network is the computer, yeah I stole it from Sun, so what?
John Jimenez_2
Occasional Advisor

Re: Where can I find an FTP script to automate

Thanks guys this worked out great. The 1st line is what I had missing. It downloaded my test perfectly. There are other of you script that looks like it may make my scripts even better. Thank you for the lesson :)
Do not worry about where you are at in your life right now, as long as you moved a little in the right direction from yesterday to today, and am moving in the right direction today for tomorrow.