Thanks for all the help. The "poll" did not work. The frustrating th
+ing is that I can get certain things to work (the connection is there
+, but the stuff I want to work times out). All I'm trying to do is g
+et/put a file on a server. You may be right that it has something to
+ do with their server (but why would the sftp work described below?).
+ Anyway, this is what I have. You will notice that the last call (s
+ftp) works ok, but the first two (get, channel) do not.
******** CODE ****************
use Net::SSH2;
use Net::SSH2::Channel;
use IO::Scalar;
use strict;
my $handle = IO::Scalar->new;;
my $ssh2 = &connect('ftp.xxxx.com','XXX','PASSWORD');
sub connect
{
my $host = $_[0];
my $user = $_[1];
my $pw = $_[2];
my $ssh2 = Net::SSH2->new();
$ssh2->connect($host);
if ($ssh2->auth_password($user, $pw))
{
print "\nIN SFTP\n";
$ssh2->poll(0);
$ssh2->scp_get('./test/out/aFile.txt', $handle);
print "Error: ", $ssh2->error(), "\n";
$handle->seek(0, 0);
_read($handle);
print "Reading channel\n";
my $chan = $ssh2->channel;
$chan->exec('cat ./test/out/aFile.txt') or die "NO Way
+\n";
print "Error: ", $chan->error(), "\n";
_read($chan);
print "Reading channel\n";
# (b) read a line at a time with SFTP
my $sftp = $ssh2->sftp;
my $file = $sftp->open('./test/out/aFile.txt') or die
+"No Way Again\n";
print "Error: ", $sftp->error(), "\n";
_read($file);
}
$ssh2->disconnect();
return $ssh2;
}
sub _read
{
my $handle = shift;
while (my $line = <$handle>)
{
print "Getting a line\n";
print $line;
}
}
****************** RESULTS *****************
IN SFTP
Error: -28LIBSSH2_ERROR_SCP_PROTOCOLTimed out waiting for SCP response
Reading channel
Error: -28LIBSSH2_ERROR_SCP_PROTOCOLTimed out waiting for SCP response
Reading channel
Error: 0SSH_FX_OK
Getting a line
aaaaaaaaaaaaaaaaaaaaaaaaa (THIS IS THE CORRECT DATA IN THE FILE)
THANKS
|