Net::SFTP vs. Net::SSH::Perl 
Author Message
 Net::SFTP vs. Net::SSH::Perl

I have a puzzling problem that is perhaps not so puzzling to those of
you who know your perl modules.

I have a script that is using BOTH the Net::SFTP and Net::SSH::Perl
modules.  Ideally, the script will create two connections to the same
server, one SFTP connection and the other an SSH connection.  The SSH
connection will execute a command (create a directory, apply the
correct permissions to the directory), the SFTP connection will upload
a file to the new directory, then the SSH connection will run another
command (apply the correct permissions to the file).  Using both
connections is necessary because SFTP ignores file attributes and
applies the incorrect permissions.

There seems to be a conflict between the two libraries. If I include
both modules at the top of the file like this:
use Net::SFTP
use Net::SSH

I can create the SFTP and SSH connections both successfully, but I
receive the following error when trying to run the $ssh->cmd("ls")
subroutine, regardless of the command I am attempting to run...

exp is not of type Math::GMP at
/usr/lib/perl5/site_perl/5.005/Net/SSH/Perl/Util/RSA.pm line 51.

Oh, and by the way, this only happens when I am connected to a Linux
server.  If I am connected to Solaris, the cmd() subroutine works
fine. Of course, I need it to work with both.

I discovered that I'm able to run the $ssh->cmd() subroutine if I
include the SFTP module using "require Net::SFTP" instead of "use
Net::SFTP", and only if I place the require statment AFTER the SSH
connection has been created.  But this is a pretty useless revelation
because now I can't create an SFTP connection... I receive a similar
error:

n is not of type Math::GMP at
/usr/lib/perl5/site_perl/5.005/Net/SSH/Perl/Buffer.pm line 160.

Ack -- what is going on ???  Is there any way to use Net::SFTP and
Net::SSH::Perl in the same perl script ???  Why would the remote OS
make any difference ???

In the meantime I will create two separate scripts, one with the ssh
commands, another with the sftp commands... not very elegant, but good
enough for now. My forehead is bruised from banging it on my desk.

Thanks if you have any help --
Megan



Tue, 13 Jul 2004 07:52:36 GMT  
 Net::SFTP vs. Net::SSH::Perl

Quote:

> I have a puzzling problem that is perhaps not so puzzling to those of
> you who know your perl modules.

> I have a script that is using BOTH the Net::SFTP and Net::SSH::Perl
> modules.  Ideally, the script will create two connections to the same
> server, one SFTP connection and the other an SSH connection.  The SSH
> connection will execute a command (create a directory, apply the
> correct permissions to the directory), the SFTP connection will upload
> a file to the new directory, then the SSH connection will run another
> command (apply the correct permissions to the file).  Using both
> connections is necessary because SFTP ignores file attributes and
> applies the incorrect permissions.

<snip, snip>

First try adding this option to your ssh constructor and see if that
helps.

auth_hosts_rsa => 0

In addition, here's some info from an email I got from Ben Trott that may
be enlightening...

"Net::SFTP requires SSH-2 because SSH-2
introduced the concept of "subsystems", or systems/protocols that run
over
the secure SSH tunnel. SFTP is such a sybsystem and thus Net::SFTP
requires
that the connection uses SSH-2"

My guess is that the Linux box doesn't support ssh2.  However, Net::SFTP
isn't strictly necessary, depending on what it is you're uploading.  This
email is also from Ben:

"However, you might be interested in taking a look at the eg/pscp script
in
the distribution directory. It implements a sort of poor man's SCP, by
which
I mean it doesn't have the added features of SCP (status bars, etc.), but
it
*does* allow you to transfer files over SSH. Basically it just works by
using cat: to read a remote file it opens up 'cat remote_file' on the
remote
server, then reads from it; and to send a local file it opens up cat on
the
remote server to read from STDIN, then sends the local file contents as
STDIN.

Currently it is inefficient, because it reads the entire file into
memory.
However, more recent developments in Net::SSH::Perl would allow this
inefficiency to go away; I just haven't made the changes to pscp yet."

Hope that helps.

Regards,

Mr. Sunblade

--
"Nothing great was ever designed by committee"

- Me



Tue, 13 Jul 2004 22:27:41 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. No ouput from Net::SSH:Win32Perl / Net::SSH::Perl

2. No ouput from Net::SSH:Win32Perl / Net::SSH::Perl

3. Net::SFTP - "ssh port mapping" problem

4. Net::Telnet and Net::SSH or ssh ?

5. NET::SSH, NET::FTP, NET::POP3 (how to detect)

6. Failed connection to sftp server via Net::SFTP

7. Net::SFTP Fails, sftp OK

8. Net::SSH::Perl::Agent and ssh-add

9. Using Net::SSH & Net::SCP

10. Net:SSH - Permission problem with ssh->cmd...

11. Net::YMSG vs. NET::YahooMessenger

12. Windows to Unix Net::SCP or SFTP, public key authentication question

 

 
Powered by phpBB® Forum Software