in reply to use (of) Net::FTP for updating

You may slap me for suggesting this (but please don't...I bruise easily), but you could try $con->dir("."). You'll need to extract the name as well as the first flag, but that shouldn't be too difficult. :)

Update: Ah, here you go. Just don't hurt me:

#!/usr/bin/perl -w use strict; use Net::FTP; # change preferences to meet your needs my $ftp_srv = 'ftp.ntua.gr'; my $ftp_usr = 'anonymous'; my $ftp_pass = 'me@somewhere.com'; my $ftp_path = '/pub/linux/slackware/slackware-9.0/'; # the main program my $con; $con = Net::FTP->new($ftp_srv, Debug => 1) or die "Unable to connect to $ftp_srv\n". $con->message ."\n"; $con->login($ftp_usr,$ftp_pass) or die "Cannot login: ". $con->message ."\n"; $con->cwd($ftp_path) or die "Cannot change to $ftp_path dir\n".$con->message ."\n"; my @ls = $con->dir('.') or die "Cannot perfom ls command\n".$con->message."\n"; my @readable = map printable_version($_), @ls; $\ = "\n"; print foreach @readable; sub printable_version { shift; /^(.).*\s([^\s]*)$/; "$1 $2"; }

antirice    
The first rule of Perl club is - use Perl
The
ith rule of Perl club is - follow rule i - 1 for i > 1

Replies are listed 'Best First'.
Re: Re: use (of) Net::FTP for updating
by atnonis (Monk) on Jun 26, 2003 at 02:05 UTC
    i think i need to get some rest, i confess
    antonis
Re: Re: use (of) Net::FTP for updating
by atnonis (Monk) on Jun 26, 2003 at 02:58 UTC
    sorry i havent clear out have i want exactly.
    i want to be able to see if it is a dir or a file. if it is a dir i want to enter into it and get the dir contect and see if it is dir or a file. if it is dir .... etc. etc. etc.
    is that possibly!?
    antonis

      Ummm...ok. I'll try to put it in a better form... REALLY UNTESTED AND SLOPPY CODE FOLLOWS:

      #!/usr/bin/perl -w use strict; use Net::FTP; # change preferences to meet your needs my $ftp_srv = 'ftp.ntua.gr'; my $ftp_usr = 'anonymous'; my $ftp_pass = 'me@somewhere.com'; my $ftp_path = '/pub/linux/slackware/slackware-9.0/'; # the main program my $con; $con = Net::FTP->new($ftp_srv, Debug => 1) or die "Unable to connect to $ftp_srv\n". $con->message ."\n"; $con->login($ftp_usr,$ftp_pass) or die "Cannot login: ". $con->message ."\n"; $con->cwd($ftp_path) or die "Cannot change to $ftp_path dir\n".$con->message ."\n"; my %dir = %{parse_dir('.')}; $\ = "\n"; print "Outputting directory ."; print $_,"\t"x2,$dir{$_} foreach sort keys %dir; my $refarr = separate_file_dir(%dir); print "Printing dirs ======================"; print foreach @{$refarr->{'dir'}}; print "Printing files ====================="; print foreach @{$refarr->{'file'}}; print "Printing links ====================="; print foreach @{$refarr->{'link'}}; # pass this the directory you want to get the listing from sub parse_dir { shift; my @ls = $con->dir($_) or die "Cannot perfom ls command\n".$con->message."\n"; my %dir; $dir{$_->[0]} = $_->[1] foreach (map parse_line($_), @ls); \%dir; } # separate the dir's and files to two arrays # send the entire hash to this baby sub separate_file_dir { my %hash = @_; my $arr1 = []; my $arr2 = []; my $arr3 = []; foreach (sort keys %hash) { # yes, I know this is bad :-/ push @$arr1, $_ if $hash{$_} eq 'dir'; push @$arr2, $_ if $hash{$_} eq 'file'; push @$arr3, $_ if $hash{$_} eq 'link'; } { dir=> $arr1, file=> $arr2, link => $arr3 }; } sub parse_line { shift; /^(.).*\s([^\s]*)$/; if ($1 eq 'd') { $a = "dir"; } # yes, I used $a, I suck...blah blah +blah elsif ($1 eq 'l') { $a = "link"; } else { $a = "file"; } [$2,$a]; }

      Ok. This code gives you two very nice subs called parse_dir which takes a string representing the directory to check and returns a hashref for which the filenames are keys and the values are dir, link, or file. separate_file_dir takes a hash as its input and returns a hashref with the keys dir, file, and link. Each value is a sorted arrayref of the associated directories, files, or links. Please note that no error checking is present for these subs. If anyone is horrified by this messy code, I apologize :-)

      antirice    
      The first rule of Perl club is - use Perl
      The
      ith rule of Perl club is - follow rule i - 1 for i > 1