dilip.patel has asked for the wisdom of the Perl Monks concerning the following question:

I am new to this group, so sorry in advance if I make any mistake. I am using perl from last one year. I want to read file varying size(1mb to 300mb ) from remote machine which having password and simultaneously want to perform operation . I tried File::Remote to read file but it dose not support host having password.

Thanks in advance for your help.

Replies are listed 'Best First'.
Re: How to Read file from remote machine?
by zentara (Cardinal) on Jul 20, 2014 at 13:01 UTC
    By remote password, I'm guessing your mean http authorization, not some cgi program. Here is a program from the Perl Cookbook
    #!/usr/bin/perl #from lwpcook use warnings; use strict; use LWP::UserAgent; my $ua = LWP::UserAgent->new; my $URL = 'http://zentara.net/zentara1.avi'; my $filename = substr( $URL, rindex( $URL, "/" ) + 1 ); #print "$filename\n"; open( IN, ">$filename" ) or die $!; print "Fetching $URL\n"; my $expected_length; my $bytes_received = 0; my $req = HTTP::Request->new(GET => $URL); my $user = 'zentara'; my $pass = 'foobar'; $req->authorization_basic($user, $pass); my $res = $ua->request($req, sub { my ( $chunk, $res ) = @_; $bytes_received += length($chunk); unless ( defined $expected_length ) { $expected_length = $res->content_length || 0; } if ($expected_length) { printf STDERR "%d%% - ", 100 * $bytes_received / $expected +_length; } print STDERR "$bytes_received bytes received\n"; # XXX Should really do something with the chunk itself print IN $chunk; } ); print $res->status_line, "\n"; close IN; exit;

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
Re: How to Read file from remote machine?
by salva (Canon) on Jul 20, 2014 at 15:19 UTC
    We need a more detailed description of your problem in order to help you effectively.

    Specifically, which network services allowing remote access to the file system are available on the server and also which operating system run in both the client and the server.

      On both client and server side it having Linux operating system. I have implemented it by using Net::SSH::Expect

      #!/usr/bin/perl -w use strict; use Net::SSH::Expect; use Data::Dumper; my ($host,$user,$password) = ('172',"abc","xyz",); my $ssh = Net::SSH::Expect->new( 'host'=>$host, 'user'=>$user, 'password'=>$password, 'timeout' => 20 ); my $login_output = $ssh->login(); my $file = "/foo/boo"; $ssh->send("cat $file"); while (my $line = $ssh->read_line()) { print "Doing operation on $line\n"; }

      But it is very slow, takes too much time to get connect with remote server and also take time to do "cat" of large file(~200mb).