3
votes

I am using Net::SFTP::Foreign with IO::Pty.

My Login Command is:

Net::SFTP::Foreign->new(host=> $server_address,
                        user => $user_id,
                        password => $password)
    or die "Could not Connect To Server $server_address: $!"; 

When I am passing invalid entry for server/user/password, it's not throwing the error message. It's simply hanging on the command line and not giving any output ever after 30+ minutes.

Please help how to handle the errors, if there is any invalid input parameters.

If I am passing all the valid values, its working fine.

1
By invalid, do you mean a wrong password? Or does this also happen when you use a $server_address that is neither a host name nor an IP address? - simbabque
Enable debugging both in the module and in ssh and post here the output: $Net::SFTP::Foreign::debug=-1; my $sftp = Net::SFTP::Foreign->new(more => '-vvv', ...); - salva
No luck even after the above update. I tried below. Net::SFTP::Foreign::debug=-1; $sftp = Net::SFTP::Foreign->new(host=> $server_address, user => $user_id, password => $password, more=>'-vvv'); But the job is still hanging off and not giving any output if I pass a wrong host name. Please help! or die "Could not Connect To Server $server_address: $!"; - Edu
include the debugging output in the question!!! - salva
Command I used: Net::SFTP::Foreign::debug=-1; $sftp = Net::SFTP::Foreign->new(more=>'-vvv', host=> $server_address, user => $user_id, password => $password); cmd line output -> OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013 debug1: Reading configuration data /etc/ssh/ssh_config debug1: Applying options for * debug2: ssh_connect: needpriv 0 ssh: Could not resolve hostname ftp_address: Name or service not known. With this code, the job is handing off and not returning any status. After adding 'timeout=>30' to the login command, it is failing the job when I pass the incorrect host name. - Edu

1 Answers

2
votes

Finally, using the following option, I am able to handle the issue. Net::SFTP::Foreign::debug=-1; $sftp = Net::SFTP::Foreign->new( host=> $server_address, user => $user_id, password => $password, more=>'-vvv', timeout=>30);

This command will handle the wrong host_name, user_id or password. The job will fail after waiting for the no.of seconds given for timeout, if it is not able to establish a connection.