1748033 Members
4606 Online
108757 Solutions
New Discussion юеВ

Re: Automate FTP

 
SOLVED
Go to solution
Rick Garland
Honored Contributor

Re: Automate FTP

My mistake, you do want globbing for the mget command.

You will want filename expansion for the mget sequence.

This is a tricky one. I would have thought the 'newer' would work. This is how the MAN quotes it.
Coolmar
Esteemed Contributor

Re: Automate FTP

I think it would work if it would take wildcards, but it seems to want the exact filename. Newer, is where those error messages are coming from.
James R. Ferguson
Acclaimed Contributor

Re: Automate FTP

Hi (again) Sally:

OK. It appears that 'mget' and 'newer' do not mix. 'newer' is a variation of the simple 'get'. Re-reading your original post, I see that you said, "...then the old one remains until the new arrives (different name each time)."

So, I assume that you don't know what the new file's name will be. I missed that the first time.

One workaround is to query the remote server for the file(s) you might find. You CAN use globbing to do this (e.g. 'ls /tmp/my*'). The file list so obtained must be written to a file on the local server. Then, have your script start a second 'ftp' session with the remote server to perform either 'get filename' or 'newer filename' to transfer the *exact* file of interest.

I have used this technique of runnning a query of a directory on a remote server; building an indexed list for a user; and then allowing the user to see and select files by that index in a second menu driving a second 'ftp' session.

BTW, "globbing" is the term used to describe the shell's expansion of filenames based on metacharacter notation (e.g. 'ls my*' would return all files beginning with "my").

Regards!

...JRF...
Coolmar
Esteemed Contributor

Re: Automate FTP

It won't let me ftp -g as "anonymous". So I can't use the globbing or no globbing..whichever it was. I tried to do an ls *.tar >file and it won't do that either. How do you print a listing of a directory to a file on the local system?
Coolmar
Esteemed Contributor

Re: Automate FTP

Got it working! I didn't realize that you don't need the ">" when listing the output to a file.

Anyway, the final part of my problem is how to send out an email if it actually downloads a file. No email is needed, of course, if it finds nothing, but if it does find something and downloads, I need an email.

Thanks!
A. Clay Stephenson
Acclaimed Contributor

Re: Automate FTP

Amazingly Sally, my script already does the email too along with that pesky error checking. You are doing error checking aren't you? In any event, you should be able to see the code in that part of the shell script that calls mailx and adapt it to your uses.
If it ain't broke, I can fix that.
Coolmar
Esteemed Contributor

Re: Automate FTP

Thanks Clay....actually that is exactly what I did. However, before running the script I did a few tests and then checked the error status and they were all "0". I only want an email if something is downloaded. It seems to errorcheck on the ftp session itself, not what happened inside the ftp session.
Coolmar
Esteemed Contributor

Re: Automate FTP

Well, I got it working. I do a count of the number of files in the directory before I run the script, and then right after....if they don't match, then there is an extra file and that would be the new one which was downloaded. Then I am emailed. Couldn't think of another way.

Thanks for all the help everyone.