Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

dbf2mysql parameter, WWWXXXAPC, wwwxxxAPC, How to unsubscrube from dategen spam, docmd.close 2585, WWWXXXDOCO, nu vot, dhcpd lease file "binding state", WWWXXXDOCO, how to setup procmail to process html2text

Links

XODOX
Impressum

#1: Perl perl recursive list ftp files

Posted on 2010-11-04 09:36:54 by Majian

--00163630f9a56b4d450494360f3d
Content-Type: text/plain; charset=ISO-8859-1

Hi ,all :

I have a trouble about the how to recur list the ftp lists with the
perl .

The result like this :
---------------------------------------------------
/dir1
/sub-dir1
test1

/dir2
/sub-dir2
test2

/dir3

/sub-dir3
test3
....
---------------------------------------------------

The following is my script :
------------------------------------------------------------ ---------------

1. #!/usr/bin/perl
2.
3. use strict;
4. use Net::FTP;
5.
6. my $host = "xxx.xxx.xx.xx";
7. my $user = "test";
8. my $pass = "xxx";
9.
10. print "Connecting to FTP Server ..."
11.
12. my $ftp = Net::FTP->new($host)
13. or die "Cannot connect the ftp server";
14.
15. $ftp->login ("$user", "$pass")
16. or die "Cannot login" , $ftp->message;
17.
18. print "Logged in ...";
19.
20. $ftp->cwd ("/");
21.
22. my @dirs = $ftp->ls ('-l');
23.
24. sub if _a_dir {
25.
26. my $dir = $_[0];
27. if ($dir =~ m/^d/){
28. $ftp->cwd("$dir") or die "Error"
29. ..... (This location is my problem )
30. }
31.
32. foreach my $sub_dir (@dirs){
33. &if_a_dir ($sub_dir);
34. }
35. $ftp->quit();

I don't know how to recursive list ftp files successfully.

Could someone can give me some suggestions?

Thanks in advance ...

--00163630f9a56b4d450494360f3d--

Report this message

#2: Re: Perl perl recursive list ftp files

Posted on 2010-11-09 03:25:14 by Thomas Brightbill

On 11/4/2010 1:36 AM, sync wrote:

> 26. my $dir = $_[0];
> 27. if ($dir =~ m/^d/){
> 28. $ftp->cwd("$dir") or die "Error"
> 29. ..... (This location is my problem )
> 30. }

I suspect that $dir contains a string that starts with the directory
attributes (eg "dwrxwrxwrc"), has some other data, and ends with the
directory name. You probably want to pass just the directory name so
you'll probably need to split out the directory name portion of $dir and
pass that to cwd.

(you can check this by adding something like

print "\$dir is $dir\n";

between lines 27 and 28)

Hope that helps,

Thomas

--
Thomas Brightbill
thomas@brightbill.net
http://www.brightbill.net


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

Report this message

#3: Re: Perl perl recursive list ftp files

Posted on 2010-11-10 05:49:02 by Chandrashekar Bhat

--001636426f9bc2387a0494ab94b2
Content-Type: text/plain; charset=ISO-8859-1

Or you can add

26. my $dir = $_[0];
>

die qq{ Please pass the directory name...} if (! -d "$dir");#
Test whether you are getting actual directory


> 27. if ($dir =~ m/^d/){
> 28. $ftp->cwd("$dir") or die "Error"
> 29. ..... (This location is my problem )
> 30. }
>


Thanks,
Chandrashekar



On Tue, Nov 9, 2010 at 7:55 AM, Thomas Brightbill <thomas@brightbill.net>wrote:

> On 11/4/2010 1:36 AM, sync wrote:
>
> 26. my $dir = $_[0];
>> 27. if ($dir =~ m/^d/){
>> 28. $ftp->cwd("$dir") or die "Error"
>> 29. ..... (This location is my problem )
>> 30. }
>>
>
> I suspect that $dir contains a string that starts with the directory
> attributes (eg "dwrxwrxwrc"), has some other data, and ends with the
> directory name. You probably want to pass just the directory name so you'll
> probably need to split out the directory name portion of $dir and pass that
> to cwd.
>
> (you can check this by adding something like
>
> print "\$dir is $dir\n";
>
> between lines 27 and 28)
>
> Hope that helps,
>
> Thomas
>
> --
> Thomas Brightbill
> thomas@brightbill.net
> http://www.brightbill.net
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
>

--001636426f9bc2387a0494ab94b2--

Report this message