1753515 Members
5221 Online
108795 Solutions
New Discussion юеВ

Perl help with FTP

 
Graham Cameron_1
Honored Contributor

Perl help with FTP

I'm looking for some Perl Wizardry to help with FTPing files to and from a (NT !) gateway.

Normally I could get by with shell scripting to connect, look for files, process them and exit.

However in this case I need to poll the FTP server every 3 seconds, so I need to connect to it over FTP, and then stay connected whilst looping forever and polling, retrieving files as I find them.

That covers the collecting of files from the gateway, I also need a parallel thread to poll the local filesystem and post files to the FTP server as they are found.

I'm not so lazy I that I won't code this myself but can someone give me some pointers to get me started with Perl??

Or is there a better tool ?

Thanks in advance

Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
2 REPLIES 2
H.Merijn Brand (procura
Honored Contributor

Re: Perl help with FTP

why not fork a ping command to the background and kill it when done?

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
A. Clay Stephenson
Acclaimed Contributor

Re: Perl help with FTP

If you have Perl 5.6.1 or later installed on your UNIX box, do a man Net::FTP and all will be revealed. Note that this will give you access to the ls functions and the mdtm (modification time) functions as well. If your do a search of the forums for Net::FTP, you should get several examples.

I will also add that it's not enough to detect a newly arrived file, you need to make certain that the file has not been modified within a given period of time. You don't want to send a file that is being written to your queue directory. Use Perl's stat() function for that.

You could also turn the world around and use one of the Free Perl's for PC's and do all of your coding on the NT box. In fact, well-written Perl scripts would work equally well in either environment. Finally, make sure that you check the status of each transfer; it's so easy to do in Perl that's it's really dumb not to. I've ported several examples doing just that and automatically resending if the status was not '2'.
If it ain't broke, I can fix that.