1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!C:/Strawberry/perl/bin/perl
use strict;
use warnings;
use Net::SFTP;
use Data::Dumper; # Ausgabe von Datenstrukturen für Debug-Zwecke; Syntax 'print Dumper ( @foo );'
my $host = "webserver";
my %args = (
user => 'user',
password => 'passwort',
debug => 'true',
);
# Make connection
my $sftp = Net::SFTP->new($host, %args);
# Check Status
$sftp->status;
print Dumper ($sftp);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
SS-L5511: Reading configuration data C:\Users\ss\.ssh\config
SS-L5511: Reading configuration data C:\WINDOWS\ssh_config
SS-L5511: Connecting to webserver, port 22.
SS-L5511: Remote version string: SSH-2.0-mod_sftp
SS-L5511: Remote protocol version 2.0, remote software version mod_sftp
SS-L5511: Net::SSH::Perl Version 2.14, protocol version 2.0.
SS-L5511: No compat match: mod_sftp.
SS-L5511: Connection established.
SS-L5511: Sent key-exchange init (KEXINIT), waiting for response.
SS-L5511: Using curve25519-sha256@libssh.org for key exchange
SS-L5511: Host key algorithm: ssh-ed25519
SS-L5511: Algorithms, c->s: aes256-ctr hmac-sha2-512 none
SS-L5511: Algorithms, s->c: aes256-ctr hmac-sha2-512 none
SS-L5511: Generating ephemeral key pair.
SS-L5511: Entering Curve 25519 Key Exchange.
SS-L5511: Sent client public key, waiting for reply.
SS-L5511: Received host key, type 'ssh-ed25519'.
SS-L5511: Host 'webserver' is known and matches the host key.
SS-L5511: Verifying server signature.
SS-L5511: Send NEWKEYS.
SS-L5511: Waiting for NEWKEYS message.
SS-L5511: Enabling encryption/MAC/compression.
SS-L5511: Sending request for user-authentication service.
SS-L5511: SSH2_MSG_EXT_INFO received
SS-L5511: SSH Extension activated: server-sig-algs=ssh-ed25519,rsa-sha2-256,rsa-sha2-512,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-rsa,ssh-dss
SS-L5511: Service accepted: ssh-userauth.
SS-L5511: Trying empty user-authentication request.
SS-L5511: Authentication methods that can continue: publickey,password.
SS-L5511: Next method to try is publickey.
SS-L5511: Trying pubkey authentication with key file 'C:\Users\ss\.ssh\id_ed25519'
SS-L5511: Authentication methods that can continue: publickey,password.
SS-L5511: Next method to try is publickey.
SS-L5511: Trying pubkey authentication with key file 'C:\Users\ss\.ssh\id_rsa'
Wrong key type at C:/Strawberry/perl/site/lib/Net/SSH/Perl/Auth/PublicKey.pm line 83.
2023-04-06T13:33:02 GwenDragonWillst du mit einem SSH-Key oder mit dem Passwort authentisieren?
2023-04-06T13:33:02 GwenDragonUnd warum nimmst du für SFTP denn den ProFTPd und nicht den OpenSSH-Server?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
my %args = (
user => 'user',
password => 'passwort',
debug => 'true',
ssh_args => {
options => [
"PasswordAuthentication yes",
"PubkeyAuthentication no"
],
#identity_files => [
# 'C:\Users\ss\.ssh\id_rsa_ssh'
#],
}
);
https://stackoverflow.com/questions/55989117/sftp-connection-failure-with-perl-netsftp-modulehttps://stackoverflow.com/questions/55989117/sftp-...EDIT: I suspected that it may be related to multiple connection failing attempts with password so I removed the password authentication from "%AUTH_MAP" in the file "app/perl-5.24.3/lib/site_perl/5.24.3/x86_64-linux/Net/SSH/Perl/AuthMgr.pm" and it connected as expected! Is there a way to force using only/first key authentication?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#!/usr/bin/perl use strict; use warnings; use 5.024; use utf8; use Net::SSH2; my $ssh2 = Net::SSH2->new(); $ssh2->connect('servana') or $ssh2->die_with_error; # $ssh2->check_hostkey( 'ask', "T:/.ssh/known_hosts" ) or $ssh2->die_with_error; $ssh2->auth_password ( "test", "test" ) or $ssh2->die_with_error; # $ssh2->auth_publickey( 'test', "T:/.ssh/id_rsa.pub", "T:/.ssh/id_rsa", "test42" ) or $ssh2->die_with_error; my $sftp = $ssh2->sftp() or $ssh2->die_with_error; my $fh = $sftp->open('/home/test/.bashrc') or $sftp->die_with_error; print while <$fh>;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
use strict; use warnings; use Net::SSH2; # Variablen festlegen my %sftp = ( sftp_server => 'server', sftp_user => 'user', sftp_pw => 'passwort', sftp_file => "zielpfad/zieldatei", ); # Verbindung zum FTP-Server aufbauen my $ssh2 = Net::SSH2->new(); $ssh2 -> connect ( $sftp {sftp_server} ) or $ssh2 -> die_with_error; $ssh2 -> auth_password ( $sftp {sftp_user} , $sftp {sftp_pw} ) or $ssh2->die_with_error; my $sftp = $ssh2 -> sftp() or $ssh2 -> die_with_error; # Datei hochladen my $fh = $ssh2 -> scp_put ( "quellpfad\\quelldatei", $sftp {sftp_file} ) or $sftp -> die_with_error; # Verbindung zum FTP-Server beenden $ssh2 -> disconnect or $ssh2 -> die_with_error;