Operating System - HP-UX
1835550 Members
2970 Online
110078 Solutions
New Discussion

Re: ftp protocol usage mode

 
SOLVED
Go to solution
Maciej Szewczykowski
Frequent Advisor

ftp protocol usage mode

how to start ftp-based connection so all the data required to start the connection (like login name, password) are taken from an indicated ascii/text file? moreover, i would like the text file mentioned to include not only login/password, but also several commands (a kind of script, actually) which will be proceeded by remote host system after executing ftp connection. is there any option of ftp command making such connection mode possible?
8 REPLIES 8
John Palmer
Honored Contributor

Re: ftp protocol usage mode

Yes, you can script ftp, something like this will work...

ftp -n << EOD
user
...
ftp commands
...
EOD

Regards,
John
Maciej Szewczykowski
Frequent Advisor

Re: ftp protocol usage mode

thanks.
if so, only commands supported by ftp protocol can go in between EOD signs, is that right?
what if i wanted to use a loop or other script structure?
regards.
John Palmer
Honored Contributor

Re: ftp protocol usage mode

If you want to loop then you have a couple of choices...

1. Have the ftp command in the loop.
2. Use a temporary command file instead of the 'here' document in the example I gave you. Write the header information to the file first (user command plus maybe cd and bin) then in your loop, write the 'put' commands or whatever then run ftp with the temp file as it's standard input. Example...

TMPF=/tmp/ftp.${$}

cat > ${TMPF} << EOD
user
cd
bin
EOD

In you loop, include the relevant commands
print "put " >> ${TMPF}

Finally run ftp
ftp < ${TMPF}
rm ${TMPF}

Regards,
John

Maciej Szewczykowski
Frequent Advisor

Re: ftp protocol usage mode

great thanks.
the problem is more simple that it perhaps seems to be. after initializing ftp connection several commands are to be executed (loops among other things). these commands - as far as i'm concerned - can belong to the pool supported by ftp protocol?
regards,
matt
Colin Topliss
Esteemed Contributor

Re: ftp protocol usage mode

You could also look at using perl if you have the time. It has a NET::FTP module which makes this sort of thing really easy to do. I have a perl program which loops around and initiates hundreds of FTP calls to retrieve files.
Darren Prior
Honored Contributor

Re: ftp protocol usage mode

Hi,

To summarise the other replies - you're writing a script that will build a script full of ftp commands. When you execute the script it builds the ftp script then executes it. If you need to have additional non-ftp commands looping - perhaps you want to use several put commands then your script needs to build those put commands and write them into the ftp script.

The attached script is one I use to ftp files newer than a certain date to a web server and illustrates this kind of looping.

regards,

Darren.
Calm down. It's only ones and zeros...
David_246
Trusted Contributor

Re: ftp protocol usage mode

This is what we do using cron :

00 15 * * * /run/this/ftpscript

/run/this/ftpscript :

ftp -v server1 mv file1 file1.old
mv file2 file2.old

--------
And
/run/this/ftp.input :
put file1
put file2
close
bye

----------------

Regs David
@yourservice
Chris Vail
Honored Contributor
Solution

Re: ftp protocol usage mode

I really recommend that you do NOT do this. Its not secure. Hard-coding usernames and passwords will only add to your maintenance burden, as well as asking for all kinds of security troubles.

Instead, install the secure utilities, and use scp instead. This very easily encrypts the file transfer using public/private key swapping. It is very easy to script, and you have no need of passwords IF it is installed correctly.

I've attached my document that shows step-by-step how to use secure copy (scp) and secure shell (ssh). Its worth the time and effort to make this work. The utilities are free from:http://www.software.hp.com/ISS_products_list.html.

Chris