Rajnikant wrote:
>
> I'm using perl 5.8.8.
> I don't have any clue about whether Net::SFTP is thread safe or not.
> 
> But I used Net::SFTP::Foreign instead of Net::SFTP and it started working
> :).
> 
> Now I'm facing some different problem :(.
> 
> If I try calling Net::SFTP::Foreign->ls method in any thread function it
> won't work.
> Following is the snipet:
> 
> use threads;
> use Net::SFTP::Foreign;
> 
> $Net::SFTP::Foreign::debug = 1;
> $remDir = '/var/opt/stcroamcommon/data/ready';
> 
> my $thread = threads->new (\&ftpThreadEntry,$host,$user,$password,$cnt);
> 
> sub ftpThreadEntry()
> {
>    my $host_l = shift;
>    my $usr = shift;
>    my $passwd = shift;
>    my $id = shift;
>    my $prot = 1;
>    my $sftp = undef;
> 
>    print ("In ftpThreadEntry func thr id $id\n");
>    my %args = (
>        "user",        $usr,
>        "password",    $passwd,
>        "more",        '-v',
>        "port",        6789
>    );
>    $sftp = Net::SFTP::Foreign->new($host_l,%args);
>    my $err = $sftp->error();  # I get 'Password not requested as expected:
> -1' msg
>    my $stat = $sftp->status(); # $stat = 'No connection'
>    if ($sftp)
>    {
>       my $files_r=$sftp->ls($remDir); # Here I get nothing in $files_r :(
>       my $filename;
> 
>       foreach my $file_r (@$files_r)
>       {
>               $filename=$file_r->{filename};
>               if($filename ne "." && $filename ne "..")
>               {
>               $filename=$remoteDir."/".$filename;
>               print("File name is $filename\n");
>               if($sftp->get($filename,$filename))
>               {
>               print("Returned something \n");
>               }
>               else
>               {
>               print("=== not returned anything\n");
>               }
>       }
>     }
> }
> $thread->join();

First of all, please bottom-post replies to threads in this group, so that
extended threads can remain comprehensible. It is something that is said almost
every day here and you really should try to be polite.

Secondly, the only obvious bug I can see is that you have assigned to $remDir
and then used $remoteDir. Bugs like this are inexcusable, as something else that
is said here almost every day is that you /must/

  use strict;
and
  use warnings;

on every program that you post here. There are no exceptions.

Thirdly, the code you have posted doesn't compile. It is broken because there is
a missing closing brace. I can guess where it belongs, but I really shouldn't
have to.

Finally, you're a C programmer aren't you? Go on, admit it! There is no reason
for all those nested blocks. Look

  foreach my $file (@$files) {

    my $filename = $file->{filename};
    next unless $filename ne '.' and $filename ne '..';
    $filename = "$remoteDir/$filename";

    print("File name is $filename\n");
    if ($sftp->get($filename, $filename)) {
      print("Returned something \n");
    }
    else {
      print("=== not returned anything\n");
    }
  }

Oh, and don't prototype subroutines. It should be

  sub ftpThreadEntry {
    :
  }

HTH,

Rob


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to