1846428 Members
2981 Online
110256 Solutions
New Discussion

Re: FTP Script

 
SOLVED
Go to solution
Oviwan
Honored Contributor

FTP Script

Hello @ll

Problem: I try do write a script which should copy all files from a directory where the date is bigger than a other date.

eg.
i go a variable
echo $lastdate
Nov 29 15:19

i need something like:
get * where date >= $lastdate

i hope its possible

Thanks
13 REPLIES 13
James R. Ferguson
Acclaimed Contributor

Re: FTP Script

Hi:

Have a look at the man pages for 'ftp(1)'. You will find a variation of 'get' called 'newer':

newer filename
...will get the file only if the modification time of the remote file is more recent that the file on the current system. If the file does not exist on the current system, the remote file is considered newer.

Regards!

...JRF...
Oviwan
Honored Contributor

Re: FTP Script

Thanks,
but i will get more than one file. can I create a loop or something like that?

it isn't possible to write 'newer *' and i don't know the name of each file. in addition i haven't any files on the local machine

ty
Rainer von Bongartz
Honored Contributor

Re: FTP Script

you should use the find command for this

Try something like

find / -newer -exec cp {} \;

this will find all files which are newer than the timestamp of and copies them to

Regards
Rainer
He's a real UNIX Man, sitting in his UNIX LAN making all his UNIX plans for nobody ...
Michael Schulte zur Sur
Honored Contributor
Solution

Re: FTP Script

Rainer,
we are talking about ftp!

Baumann,
you can read the directory with
dir into a local file and then extract the names and build a list of ftp commands. You could then create a file with the specific date/time for each file found on the remote site. With the newer command you will get only those newer than the local side. I hope the remote site is in the same time zone as yours.

greetings,

Michael
Oviwan
Honored Contributor

Re: FTP Script

Hi Michael Schulte,
thx, that's a good idea, i will try to do it. first i thought it's easier to realize it.

Regards
Michael Schulte zur Sur
Honored Contributor

Re: FTP Script

Hi,

I face this problem too. I have to get an unknown number of files and delete them after that on the remote side.
mget *
mdelete *
carries the risk of deleting more files that you transferred if in the mean time new files arrive. I am using an awk script to build an ftp script.

greetings,

Michael

BEGIN {print "cd $data3.tshps1";print "type image";}
/^X/ {print "get " tolower($1);print "delete " tolower($1)}
end

gets all files starting with X
Oviwan
Honored Contributor

Re: FTP Script

Get the whole liste

dir . filelist
that works, but in a script it doesn't

ftp -n << END_FTP
open $dbserver
user $username $password
cd $archpath
dir . file_list
bye
END_FTP

Here I must confirm with (y) the dir command. how can i disable the whole prompt?
Muthukumar_5
Honored Contributor

Re: FTP Script

Try as,

ftp -i -n $dbserver<<-FTP
user $username $password
cd $archpath
dir . file_list
bye
FTP

And,

dir . file_list will give present directory and file_list information rgt? why you can use as,

dir . itself?

hth.
Easy to suggest when don't know about the problem!
Oviwan
Honored Contributor

Re: FTP Script

Because i need a local file with all the informations in the $archpath directory from the remote machine.
Oviwan
Honored Contributor

Re: FTP Script

oops, was my mistake, sry
Michael Schulte zur Sur
Honored Contributor

Re: FTP Script

Muthukumar,

dir . file_list
is not the same as dir . and dir file_list
The above command records the information in a textfile with the name file_list. Baumann will need it to extract the names of the files to get.
The . does not work always. The remote file system must support that.
Baumann, how far are you?

Michael
Oviwan
Honored Contributor

Re: FTP Script

i did a stupid mistake. the file_list file with the informations were in an other directory :)

now i have all the filenames i need in a textfile.

#textfile
get file1
get file2
.....

how can i generate a ksh-script, that gets every file with ftp? we could open a connection for every file but i think it goes easier?
Michael Schulte zur Sur
Honored Contributor

Re: FTP Script

Have a look at my awk code snippet.
Adjust it to your environment, save it and do
awk -f awkfile file_list
You will get a list of ftp commands which you can use as input for ftp.
I use .netrc for automatic login and then
ftp -i remote < createdftpfile
In my case the filename is in position 1 and start with X.
You will have to find a filter to get the filenames. Choose the transfer method and if you want to rename or delete the file on the remote host.

Michael



BEGIN {print "cd source";print "type image";}
/^X/ {print "get " tolower{$1);print "delete " tolower($1)}
END