tags:

views:

742

answers:

5

I installed Net::SFTP::Foreign in my perl 5.8.8 and I'm trying to log in to a Secure FTP server using the below code:

use Net::SFTP::Foreign;
my $host = $tt->get_ftp_server_address();
my $sftp = Net::SFTP::Foreign->new("$host",
                                     {user=>$tt->get_location_user_name(),
                                     password=>$tt->get_location_user_password(),
                                     port=>'22'});

The line where I try to call Net::SFTP::Foreign->new fails without throwing any error on me.

+1  A: 

I think the constructor is expecting a hashtable and not a reference to a hash. Try removing the braces in your call:

my $sftp = Net::SFTP::Foreign->new("$host",
                                     user=>$tt->get_location_user_name(),
                                     password=>$tt->get_location_user_password(),
                                     port=>'22');
mobrule
Same thing happens
goe
Do I need to install anything else on a Windows machine for this lib to work properly?
goe
@goe Did you read the documentation? Note **Net::SFTP::Foreign does not requiere (sic) a bunch of additional modules and external libraries to work, just the OpenBSD SSH client (or any other client compatible enough).**
Sinan Ünür
+2  A: 

I'm reacting on your comment "Do I need to install anything else on a Windows machine for this lib to work properly?" here.

The readme states you need to have an external SSH2 client reachable from your PATH. Could that be the problem? The module is known to work on windows.

Leon Timmermans
What does this mean exactly? That I need to install windows based app to support SFTP and then pass the path to it in the "Net::SFTP::Foreign->new" call?
goe
I installed WinSCP on my machine but how do I let the "Net::SFTP::Foreign->new" know that it's there?
goe
In the constructor, you can specify in the %args your ssh client with 'ssh_cmd' key - not sure if you can use WinSCP from the command line
ccheneson
+2  A: 

You can also set the 'debug' to 1 in the %args to the constructor

From the Net::SFTP::Foreign doc:

debug => 1 if set to a true value, debugging messages will be printed out. The default is false.

Edit: Try $Net::SFTP::Foreign::debug = 1;

From the source of the 1.56_04 version:

we make $Net::SFTP::Foreign::Helpers::debug an alias for $Net::SFTP::Foreign::debug so that the user can set it without knowing anything about the Helpers package!

our $debug;

ccheneson
there's no debug => 1 in that doc
goe
Oops my bad,was looking at a older version of the module.
ccheneson
+1  A: 

Password authentication is not supported on Windows unless you use Cygwin Perl. You will have to install Expect also.

Development versions (currently, 1.56_08) can be used with Net::SSH2, so you get a rich SFTP client and password authentication.

Net::SFTP::Foreign can also work with plink (a utility that comes with Putty), that combination supports password authentication under Windows but it is not completely secure.

salva
A: 

In addition to the possibility of turning on debugging, note that the documentation clearly states:

An explicit check for errors should be included always after the constructor call:

my $sftp = Net::SFTP::Foreign->new(...);
$sftp->error and die "SSH connection failed: " . $sftp->error;

So, printing out that error message would be the first step in diagnosing issues.

Sinan Ünür