LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-22-2007, 01:02 AM   #1
kshkid
Member
 
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Rep: Reputation: 30
listing files Net::FTP


Hi All,

Am trying to use Net::Ftp

but unable to list the files available in the ftp server.

When I use,

$ftp->dir()
(or)
$ftp->ls()
it returns a value like ARRAY(0x89f1092)

how to retrieve the file listing from that /

Thanks
 
Old 05-22-2007, 02:02 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,696
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
Quote:
Originally Posted by kshkid
Hi All,

Am trying to use Net::Ftp

but unable to list the files available in the ftp server.

When I use,

$ftp->dir()
(or)
$ftp->ls()
it returns a value like ARRAY(0x89f1092)

how to retrieve the file listing from that /

Thanks
you just do @files=$ftp->ls(); then you can manipulate the @files array
 
Old 05-22-2007, 02:11 AM   #3
kshkid
Member
 
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Original Poster
Rep: Reputation: 30
I tried that already, but didnt work !

this is the script and the output

Code:
#! /opt/third-party/bin/perl

use Net::FTP;

$server = "ftpserver";
$debuglvl = 1;
$user = "user";
$pass = "password";

$ftp = Net::FTP->new($server, Debug => $debuglvl ) || die "Unable to connect to $server $@ \n";

$ftp->login($user, $pass) || die "Unable to login. ", $ftp->message;

$ftp->ascii || die "Unable to set mode to ascii. ", $ftp->message;

$ftp->cwd("/tmp/") || die "Unable to change directory", $ftp->message;

@files = $ftp->ls() || die "Unable to ls. !!! ", $ftp->message;

foreach (@files) {
  print $_ . "\n";
}

$ftp->quit;

exit 0
Code:
Net::FTP=GLOB(0x87ca6b0)<<< 226 Closing data connection. Transferred 5280 bytes.
ARRAY(0x89154d0)
Net::FTP=GLOB(0x87ca6b0)>>> QUIT
Net::FTP=GLOB(0x87ca6b0)<<< 221 Session Ended. Downloaded 0KB, Uploaded 0KB.
 
Old 05-22-2007, 02:15 AM   #4
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,287

Rep: Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034
Try this header:

#!/opt/third-party/bin/perl -w
use strict;

and note that the string concat in perl is '.', not ',' eg;

$ftp->login($user, $pass) || die "Unable to login. ".$ftp->message;
Also, it is preferred to use 'or' here, not '||' .
 
Old 05-22-2007, 02:25 AM   #5
kshkid
Member
 
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by chrism01
Try this header:

#!/opt/third-party/bin/perl -w
use strict;

and note that the string concat in perl is '.', not ',' eg;

$ftp->login($user, $pass) || die "Unable to login. ".$ftp->message;
Also, it is preferred to use 'or' here, not '||' .
No, it didnt work!

The same output

ARRAY(oxhex value) and no files being displayed
 
Old 05-22-2007, 03:20 AM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,696
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
hmm strange, it seems the array is not derefenced. maybe you can try dereferencing and see.
 
Old 05-22-2007, 04:13 AM   #7
kshkid
Member
 
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by ghostdog74
hmm strange, it seems the array is not derefenced. maybe you can try dereferencing and see.

Excellent that worked!

Since the list of files is a long name,

I think a reference is returned and not the list of actual files.

Not sure of the reason

Thanks a lot!

Last edited by kshkid; 05-22-2007 at 06:59 AM.
 
Old 05-22-2007, 06:31 AM   #8
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,696
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
Quote:
Originally Posted by kshkid
Excellent that worked!

Since the list of files is a long name,

I think a reference is returned and not the list of actual files.

Not sure of the reason

Thanks of the lot!
no problem,just a guess , since things like ARRAY(xXXx) usually indicates a reference.
 
Old 05-22-2007, 07:01 AM   #9
kshkid
Member
 
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Original Poster
Rep: Reputation: 30
Quote:
Also, it is preferred to use 'or' here, not '||' .

Could you please explain why it is preferred to use 'or' and not '||'. ?

I hope both have got the same meaning !

Thanks
 
Old 05-22-2007, 08:15 AM   #10
0.o
Member
 
Registered: May 2004
Location: Raleigh, NC
Distribution: Debian, Solaris, HP-UX, AIX
Posts: 208

Rep: Reputation: 35
Could you post the resulting code from this?
 
Old 05-22-2007, 08:39 AM   #11
kshkid
Member
 
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by 0.o
Could you post the resulting code from this?
Sorry! Could you please rephrase your request ?

Thanks!
 
Old 05-22-2007, 08:40 AM   #12
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,696
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
Quote:
Originally Posted by kshkid
Sorry! Could you please rephrase your request ?

Thanks!
he's saying to post your working code.
 
Old 05-22-2007, 08:44 AM   #13
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,696
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
Quote:
Originally Posted by kshkid
Could you please explain why it is preferred to use 'or' and not '||'. ?

I hope both have got the same meaning !

Thanks
here's what i think
Code:
 $var = EXPR1 || EXPR2; #same as $var = ( EXPR1 || EXPR2)
and
Code:
 $var = EXPR1 or EXPR2; # same as   ( $var = EXPR1) or EXPR2;
correct me if i am wrong.
 
Old 05-22-2007, 12:22 PM   #14
kshkid
Member
 
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Original Poster
Rep: Reputation: 30
But what difference its going to make,

with

Code:
open(FILE, "<", "list") || die "Unable to open file <$!>\n";
Code:
open(FILE, "<", "list") or die "Unable to open file <$!>\n";

Both are definitely the same !
 
Old 05-23-2007, 03:50 AM   #15
mechdave
Member
 
Registered: Apr 2007
Location: Adelaide, Australia
Distribution: Ubuntu 8.10 and 7.10 server
Posts: 95

Rep: Reputation: 15
It is just easier to read this way:
Code:
open(FILE, "<", "list") or die "Unable to open file <$!>\n";
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ftp listing does not work Lotharster Linux - Newbie 2 11-28-2005 07:42 AM
Recursively listing files over FTP? overbored Linux - Software 4 10-14-2004 12:12 PM
Getting Apache to spawn FTP listing? Mamour Linux - Networking 1 09-02-2003 03:52 PM
how can I restrict ftp users listing files from a pure-ftp server adrianmak Linux - Networking 2 12-31-2002 08:23 AM
Ftp listing problem piranha Linux - Networking 1 01-21-2002 12:35 AM


All times are GMT -5. The time now is 05:00 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration