Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

FTP and LS or DIR

37 views
Skip to first unread message

Jag Thripp

unread,
Jan 7, 2010, 2:19:04 PM1/7/10
to begi...@perl.org
Hello first question, maybe one of many!

Code running on a windows machine connecting to Linux box.

I am trying to capture an ls\dir command into a file from an FTP
connection, similar to ls -lA > Ls.txt.

I am trying to monitor files in a folder on a remote Red Hat server to
make sure that the files do not get out of sequence.

Sample code to date.

use Net::FTP;

use warnings;

use diagnostics;

my $filename;

print "Retrieving file listing from Red hat machine\n";

my $ftp=Net::FTP->new("Red hat machine ", Debug => 0) or die "Cannot
locate Red hat machine: $@ ";

$ftp->login($usernam,$passwd) or die "Cannot login ", $ftp->message;

$ftp->cwd("/some/path") or die "Cannot change working directory ",
$ftp->message;

$ftp->ls;

$ftp->quit;


Information contained in this email message is intended only for use of the individual
or entity named above. If the reader of this message is not the intended recipient, or
the employee or agent responsible to deliver it to the intended recipient, you are hereby
notified that any dissemination, distribution or copying of this communication is strictly
prohibited. If you have received this communication in error, please immediately notify
the sender by email and destroy the original message.

SKY NETWORK TELEVISION LTD
10 Panorama Rd, Mt Wellington
PO Box 9059, Newmarket, Auckland, NZ

Uri Guttman

unread,
Jan 7, 2010, 2:30:20 PM1/7/10
to Jag Thripp, begi...@perl.org
>>>>> "JT" == Jag Thripp <jth...@skytv.co.nz> writes:

JT> Hello first question, maybe one of many!

it helps if you actually ASK a question. you explain your goal, show
some code but say nothing about what isn't working or what errors you
get or ask a question.

JT> Code running on a windows machine connecting to Linux box.

JT> I am trying to capture an ls\dir command into a file from an FTP
JT> connection, similar to ls -lA > Ls.txt.

JT> use Net::FTP;

JT> use warnings;

JT> use diagnostics;

use strict ;

JT> my $filename;

JT> $ftp->ls;

from the Net::FTP docs:

ls ( [ DIR ] )

Get a directory listing of DIR, or the current directory.

In an array context, returns a list of lines returned from the
server. In a scalar context, returns a reference to a list.

you call ls in a void context. did you expect the output to magically be
stored somewhere? try assigning the result of the call and then printing
or using that.

uri

--
Uri Guttman ------ u...@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------

John W. Krahn

unread,
Jan 7, 2010, 2:36:06 PM1/7/10
to Perl Beginners
Jag Thripp wrote:
> Hello first question, maybe one of many!

Hello,

> Code running on a windows machine connecting to Linux box.
>
> I am trying to capture an ls\dir command into a file from an FTP
> connection, similar to ls -lA > Ls.txt.
>
> I am trying to monitor files in a folder on a remote Red Hat server to
> make sure that the files do not get out of sequence.
>
> Sample code to date.
>
> use Net::FTP;
> use warnings;
> use diagnostics;
>
> my $filename;
>
> print "Retrieving file listing from Red hat machine\n";
> my $ftp=Net::FTP->new("Red hat machine ", Debug => 0) or die "Cannot locate Red hat machine: $@ ";
> $ftp->login($usernam,$passwd) or die "Cannot login ", $ftp->message;
> $ftp->cwd("/some/path") or die "Cannot change working directory ", $ftp->message;
> $ftp->ls;

open my $FH, '>', 'Ls.txt' or die "Cannot open 'Ls.txt' $!";
print $FH $ftp->ls;
close $FH;

> $ftp->quit;

John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity. -- Damian Conway

0 new messages