Hello monks!
Im trying to learn Net:FTP module for checking and downloading updates for my linux box.
I have writen the following code
#!/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->ls('.')
or die "Cannot perfom ls command\n".$con->message."\n";
#print "$_\n" foreach @ls;
my $what;
foreach $what (@ls) {
print "$what\n";
if (-d $what) {
print "DIR DEBUG\n";
print "$what is a dir\n";
}elsif (-f $what) {
print "FILE DEBUG\n";
print $what .' is a file '.$con->size($what)."\n";
}
}
which does the following
1. Connect to the ftp server
2. Login with anonymous account
3. Change to a directory
4. Get a list of the contect of the directory and store it to an array (called @ls)
5. Check array where is file and where is directory
S**t! we are checking to a list so we CANT see if it is a file or a directory
How can we solve this problem, i cant figure it out
atnonis
----------------------
use strict or die;
----------------------
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.