1748027 Members
4839 Online
108757 Solutions
New Discussion юеВ

Re: Automate FTP

 
SOLVED
Go to solution
Coolmar
Esteemed Contributor

Re: Automate FTP

Thanks for all the responses....I think James hit it with "newer". I am going to try that.

S.
Coolmar
Esteemed Contributor

Re: Automate FTP

hmmmmmm....I sent my previous reponse too soon. I am wondering, would the files have to have the same name with "newer"? The problem is that the name always changes...the one consistent thing is that it is always a tar file. However, I can't say "newer *.tar". What I want to accomplish is to check the ftp server throughout the day for the new tar file. If the tar file that exists is what I already have in my directory, then done. If it is a new file, that I don't have...download it.

Thanks,
Rick Garland
Honored Contributor

Re: Automate FTP

Use mget (instead of get) and specify 'newer *.tar'

The mget accepts wildcards.

Coolmar
Esteemed Contributor

Re: Automate FTP

I tried that, and this was what came back:

ftp> mget newer *.tar
newer: The system cannot find the file specified.
mget dat-4624.tar? y
200 PORT command successful.
150 Opening ASCII mode data connection for dat-4624.tar(7710720 bytes).


Then it starts "getting" the file. I must not be using the correct syntax or something. Shouldn't it determine that there is only one tar file there, so that would be the one....and it is not newer than what I have and therefore not download it?
Rick Garland
Honored Contributor

Re: Automate FTP

What happens when you turn off the prompt?

prompt off
mget newer *.tar
...
Coolmar
Esteemed Contributor

Re: Automate FTP

It starts getting the file. However, I already have that one, so I don't want it to get it.

prompt off
Interactive mode off.
ftp> mget newer *.tar
newer: The system cannot find the file specified.
local: dat-4624.tar remote: dat-4624.tar
200 PORT command successful.
150 Opening ASCII mode data connection for dat-4624.tar(7710720 bytes).
Coolmar
Esteemed Contributor

Re: Automate FTP

Is there an equivalent to using grep within an ftp session? Like, if I could list the files and grep on the tar files, that would leave that one...then awk everything but the name of the file to a variable...and mget newer $var ? or is that asking too much of poor ftp?
A. Clay Stephenson
Acclaimed Contributor

Re: Automate FTP

The most important glaring problem with these other approaches is that there is zero error checking. If you use the method I suggested and check the exit status of the Perl script itself then if it's zero then all is well -- meaning the complete file got there intact. The good news (maybe) is that you really don't have to know any Perl at all. All of the logic is still in the shell script that calls the Perl script. You simply have to feed it arguments and check the exit status.
If it ain't broke, I can fix that.
Rick Garland
Honored Contributor

Re: Automate FTP

If you use the -g option (noglobbing) instead of the newer, will that still download the file?



Coolmar
Esteemed Contributor

Re: Automate FTP

You mean start the seesion with -g then mget *tar?

ftp -g
mget *.tar

BTW, what does "globbing mean"