Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using login/password with Net::SFTP

Status
Not open for further replies.

zeevam

Programmer
Feb 27, 2002
11
US
I am having problems with the following pseudocode:

if user's remote server login/password valid{
sftp file to remote server
}else{
throw an error
}

Basically my application uses ftp currently to do this. The user enters in his/her login and password to copy a file from the local server to a specified remote server on the front end. I am not sure if it is feasible or not to do this with SFTP. Thanks.
 
from the docs, looks as if you code should look something like

my $sftp = Net::SFTP->new(
$host, {
user => 'mike',
password => 'password'
}
);

$sftp->get(
'/etc/hosts', # remote file to get
'/tmp/hosts' # into this local filename
);

is that what you're doing? Mike
"Experience is the comb that Nature gives us after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
Here is the ftp code that I currently use:


my $ftp ='';
$ftp = Net::FTP->new("$target_server", timeout => 999999999999);
if ($ftp->login("$login_name","$password"))
{
$ftp->cwd("$initial_dir");
$ftp->put("/var/tmp_tar/$tar_filename", "$tar_filename");
$ftp->quit;
}
else {
print &quot;<SCRIPT LANGUAGE=\&quot;JavaScript\&quot;>\n&quot;;
print &quot;alert(\&quot;Cannot Connect! Password or login name may be incorrect! Try again.\&quot;)\n&quot;;
print &quot;</SCRIPT>\n&quot;;
}

Is their an easy way to convert this to sftp?
 
From what I read in the sftp documentation it would seem that you can convert you ftp code to sftp -- but you need to have a few other things (ssh for instance) running first.

Have you reviewed the sftp documentation? Mike
&quot;Experience is the comb that Nature gives us after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
I have read through the sftp documentation and I am not finding any login methods such as in ftp. The big issue is trying to get the if the login fails, then throw an error part. I tried using Net::SSH::perl to check the login/password but that didn't work properly. Let me know if you have any ideas. Thanks...
 
From the sftp documentation, found at
USAGE
Net::SFTP->new($host, %args)
Opens a new SFTP connection with a remote host $host, and returns a Net::SFTP object representing that open connection.

%args can contain:

* user

The username to use to log in to the remote server. This should be your SSH login, and can be empty, in which case the username is drawn from the user executing the process.
See the login method in Net::SSH::perl for more details.

* password

The password to use to log in to the remote server. This should be your SSH password, if you use password authentication in SSH; if you use public key authentication, this argument is unused.
See the login method in Net::SSH::perl for more details.
Mike
&quot;Experience is the comb that Nature gives us after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top