On Fri, Feb 6, 2009 at 13:27, jk <jayantachar...@gmail.com> wrote:
> i m a beginner to perl . i want to write a perl program to Connect to
> an FTP server and get or put files and also to Automate the one-time
> transfer of many files to download the file everyday, which have
> changed since yesterday. i have written the first part of the program
> i.e.connect,get and put files, which is very easy the examples are
> easily available on the net.But i have no information about the second
> part about the automation. kindly help me. if anyone can provide me
> the code i will be grateful to him/her.
snip

You have a bit of a problem here.  The FTP standard* does not specify
what a server should return when asked to provide information about a
file:

    Since the information on a file may vary widely from system
    to system, this information may be hard to use automatically
    in a program, but may be quite useful to a human user.

Now, if you always use the same server you may be able to figure out
what format it uses.  Here is a small program that gets the dates from
the ftp server that ftp.kernel.org uses:

#!/usr/bin/perl

use strict;
use warnings;

use Net::FTP;

my $ftp = Net::FTP->new("ftp.kernel.org")
        or die "couldn't connect: $@";

$ftp->login("ftp", "ftp")
        or die "couldn't login: ", $ftp->message;


#an example of both types of format, it seems to use month name, day
#and year for dates in previous years and month name, day and time
#for dates in the current year
#drwx------    2 0        0               6 Oct 02  2005 lost+found
#drwxrwsr-x   11 536      536          4096 Sep 23 23:53 pub

my $year = (localtime)[5] + 1900;
for my $file ( map { [(split)[5 .. 8]] } $ftp->dir) {
        if ($file->[2] =~ /:/) {
                $file->[2] = $year;
        }
        print join(" ", @$file), "\n";
}

$ftp->quit;

* http://www.ietf.org/rfc/rfc959.txt

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to