×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Using login/password with Net::SFTP

Using login/password with Net::SFTP

Using login/password with Net::SFTP

(OP)
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.

RE: Using login/password with Net::SFTP

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.

RE: Using login/password with Net::SFTP

(OP)
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 "<SCRIPT LANGUAGE=\"JavaScript\">\n";
                print "alert(\"Cannot Connect! Password or login name may be incorrect!  Try again.\")\n";
                print "</SCRIPT>\n";
        }

Is their an easy way to convert this to sftp?

RE: Using login/password with Net::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
"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.

RE: Using login/password with Net::SFTP

(OP)
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...

RE: Using login/password with Net::SFTP

From the sftp documentation, found at www.cpan.org

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
"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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close