ืžืขื›ืฉื™ื• ืคื•ืกื˜ื™ื ื—ื“ืฉื™ื ืž-Usenet ืœื ื™ื•ืคื™ืขื• ื•ืื™ ืืคืฉืจ ืœื”ื™ืจืฉื ืœืชื•ื›ืŸ ืž-Usenet ื‘ืงื‘ื•ืฆื•ืช Google. ื”ืชื•ื›ืŸ ืฉื›ื‘ืจ ืคื•ืจืกื ืขื“ื™ื™ืŸ ื™ื•ืคื™ืข.

help with making an sftp connection

5 ืฆืคื™ื•ืช
ืžืขื‘ืจ ืœื”ื•ื“ืขื” ื”ืจืืฉื•ื ื” ืฉืœื ื ืงืจืื”

Brent Wood via beginnersโ€

ืœื ื ืงืจืื”,
16 ื‘ืืคืจืณ 2023, 17:45:0616.4.2023
ืขื“ begi...@perl.orgโ€
Hi,

I'm not a perl coder, (though have written a few very simple Perl scripts when necessary) but now I need to write a Perl script to transfer specified files from one computer to another. I have scribbled out a script a while back using FTP, but now need to use SFTP. I can re-use most of the old FTP code/logic, but need some help to make the actual connection.

It is a secure (no external connectivity) network, with no public/private key security available, so authentication just via user/password

Some Googling for how I might do this in Perl has thrown up several possibilities, more confusing than informative, so I'm not sure how to best do this.

It looks like Net::SFTP::Foreign might best fit my needs, but I'm open to suggestions.


Advice or a code snippet on how to make the connection should be enough, and much appreciated!!



Thanks,

Brent Wood

Uri Guttmanโ€

ืœื ื ืงืจืื”,
17 ื‘ืืคืจืณ 2023, 1:00:0617.4.2023
ืขื“ begi...@perl.orgโ€
On 4/17/23 00:46, Brent Wood via beginners wrote:
Cheers Jim,

I have already found that resource and tried a few ways to make it work, but it always seems to invoke public/private key authentication, which is not available on the remote system


my perl is:
ย ย ย 
ย ย ย  my %args = (
ย ย ย ย ย ย ย ย  user => '$user',
ย ย ย ย ย ย ย ย  password => '$password',

you seem to be quoting the variables which will not use their values. drop the quotes on all single vars and try it it again

ย ย ย ย ย ย ย ย  ssh_args => {
ย ย ย ย ย ย ย ย ย ย ย ย  user => '$user',
ย ย ย ย ย ย ย ย ย ย ย ย  password => '$password',
ย ย ย ย ย ย ย ย ย ย ย ย  protocol=>'2,1',
ย ย ย ย ย ย ย ย ย ย ย ย  debug => 1,
ย ย ย ย ย ย ย ย  }
ย ย ย  );

my $sftp=Net::SFTP->new($server, %args)
ย ย ย  or die "could not open connection to $server\n";

uri

-- 
https://uriguttman.blogspot.com/
A Long Strange Trip
A blog about computers, food, my life and silliness.

Brent Wood via beginnersโ€

ืœื ื ืงืจืื”,
17 ื‘ืืคืจืณ 2023, 1:00:0617.4.2023
ืขื“ Perl Beginners,Jim Gibsonโ€
Cheers Jim,

I have already found that resource and tried a few ways to make it work, but it always seems to invoke public/private key authentication, which is not available on the remote system


my perl is:
ย ย ย 
ย ย ย  my %args = (

ย ย ย ย ย ย ย ย  user => '$user',
ย ย ย ย ย ย ย ย  password => '$password',
ย ย ย ย ย ย ย ย  ssh_args => {
ย ย ย ย ย ย ย ย ย ย ย ย  user => '$user',
ย ย ย ย ย ย ย ย ย ย ย ย  password => '$password',
ย ย ย ย ย ย ย ย ย ย ย ย  protocol=>'2,1',
ย ย ย ย ย ย ย ย ย ย ย ย  debug => 1,
ย ย ย ย ย ย ย ย  }
ย ย ย  );

my $sftp=Net::SFTP->new($server, %args)
ย ย ย  or die "could not open connection to $server\n";

resulting in:
...
SH97R: Service accepted: ssh-userauth.
SH97R: Trying empty user-authentication request.
SH97R: Authentication methods that can continue: publickey,password.
SH97R: Next method to try is publickey.
SH97R: Publickey: testing agent key 'woodb@woodb-HP-EliteDesk-800-G6-Desktop-Mini-PC'
SH97R: Authentication methods that can continue: publickey,password.
SH97R: Next method to try is publickey.
SH97R: Trying pubkey authentication with key file '/home/baw/.ssh/id_rsa'
Wrong key type at /usr/local/lib/x86_64-linux-gnu/perl/5.34.0/Net/SSH/Perl/Auth/PublicKey.pm line 83.




I figure I need to disable the public key authentication method so only the password method is used, which will hopefully work.

If someone can post a Perl command to instantiate an SFTP connection with just the host, user & password parameters I think I can wrap everything else I need around that.

I'm guessing I need to set PubkeyAuthentication to no & PasswordAuthentication to yes, but can't work out how to pass those parameters to when trying to establish the connection.


Thanks,

Brent

On Monday, April 17, 2023 at 10:55:31 AM GMT+12, Jim Gibson <jsgi...@icloud.com> wrote:


Perl has a repository of user-submitted modules called Comprehensive Perl Archive Network (CPAN). Net::SFTP::Foreign can be installed from there, and it looks like a good candidate, as does Net::SFTP. The two modules use different methods for invoking the SFTP protocol. I would try one and, if that doesnโ€™t work, the other. You can also search CPAN for other FTP and SFTP modules. Most modules come with their own documentation and sample code. See this link for Net::STFP::Foreign:


Try what that gives you, and come back here if you have any specific questions or problems. It is always good to give it a try for yourself before asking for help. Post what you try.
Jim Gibson



Brent Wood via beginnersโ€

ืœื ื ืงืจืื”,
17 ื‘ืืคืจืณ 2023, 5:30:1017.4.2023
ืขื“ begi...@perl.org,Uri Guttmanโ€
More detail, thanks for your time...


This is to test the Perl script on a local (Linux) system, copying a file from /tmp to another directory.

I can use command line sftp to copy a file fine with the user/password connection, so there is not a problem with sftp, user/password etc on the system.

This Perl script executes without error, but hangs on $sftp = Net::... (prints start, never prints done)

If I take out the password assignment, I'm prompted for a password and it then works fine. With it there, it hangs.

Can anyone help me get this working with a password passed as a parameter?

use Net::SFTP::Foreign;
use IO::Pty;
use feature say;

$host = "127.0.0.1";
$user = "baw";
$pass = "......";

say "start";

$sftp = Net::SFTP::Foreign->new($host,
ย ย  ย ย ย  ย ย ย  ย ย ย ย ย ย ย ย  user => $user,
ย ย  ย ย ย  ย ย ย  ย ย ย ย ย ย ย ย  password => $pass,
ย ย ย ย ย ย  ย ย ย  ย ย ย  ย ย ย ย ย ย ย ย  more => [qw(-o PreferredAuthentications=password -o PasswordAuthentication=yes -o BatchMode=yes)]
ย ย ย  );

say "done";

0 ื”ื•ื“ืขื•ืช ื—ื“ืฉื•ืช