Operating System - HP-UX
1833786 Members
2504 Online
110063 Solutions
New Discussion

FTP files in all subdirectories

 
SOLVED
Go to solution
Wendy W. Lou
New Member

FTP files in all subdirectories

How do I automate the FTP so I can get files in a directory, plus files in all subdirectories recursively?
Any help is greatly appreciated!
7 REPLIES 7
James R. Ferguson
Acclaimed Contributor

Re: FTP files in all subdirectories

Hi Wendy:

You could do something like this:

#!/usr/bin/sh
for X in `find /tmp/dummydir -type f`
do
{ echo "open thehost
user uuu ppp
put $X $X.dup
close"
} | ftp -i -n -v
done

...JRF...
Stefan Farrelly
Honored Contributor

Re: FTP files in all subdirectories

Theres no simple way to do this with the current ftp program on hp-ux. It is possible, but would involve a complicated script. You would have to do something like ftp to the remote site, do an ls -R - and send this output to a local file, close the ftp connection. Convert the output file from the ls -R into commands for a subsequent ftp connection, one where you cd to each subdir in turn, mget *, then cd to the next dir etc. This would take some time to write and get working correctly.

Far easier to download a different version of ftp from the HP-UX porting centre which will allow recursive ftp of files and subdirectories, eg;

http://hpux.connect.org.uk/hppd/hpux/Networking/FTP/ftpcopy-0.3.5/
Im from Palmerston North, New Zealand, but somehow ended up in London...
James R. Ferguson
Acclaimed Contributor

Re: FTP files in all subdirectories

Hi Wendy (again):

Ah...If by "get" you mean "pull" then I agree with Stefan. I read "get" as "process" and so provided a suggestion to "put" or "push" files!

Regards! :-))

...JRF...
Wendy W. Lou
New Member

Re: FTP files in all subdirectories

Thanks James and Stefan for your help.
If I read James' script correctly, it does not read the subdirectories recursively. (Excuse my limited knowledge on scripts.) I am trying to ftp one directory tree from Unix to NT, hopefully running from NT side. I am trying to automate this.
I guess there may not be an easy way to do it (as Stefan indicated).
Mladen Despic
Honored Contributor

Re: FTP files in all subdirectories

Wendy,

In case you haven't considered:

If your unix SA could install Samba on the unix server
(it's free!), you would be able to use the shared files/directories just like from another NT system.

Mladen
Mladen Despic
Honored Contributor
Solution

Re: FTP files in all subdirectories

Wendy,

It looks like James didn't quite test his script. I think after "do" line, you could insert something like:

XDIR=`dirname $X`
XFILE=`basename $X`
cd $XDIR

and then change the line:

put $X $X.dup

to

put $XFILE $XFILE.dup


This script will not duplicate the entire directory tree.
It will ftp all the files (including the files under subdirectories), but they will all end up in a single directory on your NT system.

If you'd like to duplicate the entire directory tree, you could create a tar archive, then ftp the archive to your NT system and then use Winzip on your NT system.
The unix part can be made automatic via a script
(schedule it as a cron job if you wish) - something like this:

cd
tar cvf /tmp/archive.tar
cd /tmp
{echo "open
user
put archive.tar
close"
} | ftp -i -n -v
James R. Ferguson
Acclaimed Contributor

Re: FTP files in all subdirectories

Hi:

A point of clarification (honor), please. The script I posted was quick and crude, but *was tested*. My intention was merely to show one way to recursively descend directories, and pick files to ftp.

No points, please, Wendy.

...JRF...