end0tknr's kipple - web写経開発

太宰府天満宮の狛犬って、妙にカワイイ

Net::SFTP は apache環境で利用不可? ... Net::SFTP::Foreign 使いましょう

ftp->sftpへのプロトコル対応が必要だったので、あまり考えずに Net::FTP -> Net::SFTP に移行しようとしたら、Net::SFTP->new() でエラーにならないものの、sftpで接続できない。

...同様のperl scriptをコマンドラインで実行すると、成功しましたが。

use Net::SFTP;
my $ftp = Net::SFTP->new('ホスト名',
                         user=>'ないしょ', password=>'ないしょ',
                         debug=>1 );

↑こう書くと、Net::SFTP->new() では、「sftp: Sending SSH2_FXP_INIT」の後に「sftp: Remote version: 3」が続くはずなのに..停止(hangup?)

colinux: Reading configuration data /.ssh/config
colinux: Reading configuration data /etc/ssh_config
colinux: Connecting to ないしょ.co.jp, port 22.
colinux: Remote protocol version 2.0, remote software version WeOnlyDo 2.1.3
colinux: Net::SSH::Perl Version 1.35, protocol version 2.0.
.olinux: No compat match: WeOnlyDo 2.1.3
colinux: Connection established.
colinux: Sent key-exchange init (KEXINIT), wait response.
colinux: Algorithms, c->s: 3des-cbc hmac-sha1 none
colinux: Algorithms, s->c: 3des-cbc hmac-sha1 none
colinux: Entering Diffie-Hellman Group 1 key exchange.
colinux: Sent DH public key, waiting for reply.
colinux: Received host key, type 'ssh-dss'.
colinux: Host 'ないしょ.co.jp' is known and matches the host key.
colinux: Computing shared secret key.
colinux: Verifying server signature.
colinux: Waiting for NEWKEYS message.
colinux: Send NEWKEYS.
colinux: Enabling encryption/MAC/compression.
colinux: Sending request for user-authentication service.
colinux: Service accepted: ssh-userauth.
colinux: Trying empty user-authentication request.
colinux: Authentication methods that can continue: password,publickey.
colinux: Next method to try is password.
colinux: Trying password authentication.
colinux: Login completed, opening dummy shell channel.
colinux: channel 0: new [client-session]
colinux: Requesting channel_open for channel 0.
colinux: channel 0: open confirm rwindow 131072 rmax 98304
colinux: channel 1: new [client-session]
colinux: Requesting channel_open for channel 1.
colinux: Sending subsystem: sftp
colinux: Requesting service subsystem on channel 1.
colinux: channel 1: open confirm rwindow 131072 rmax 98304
colinux: sftp: Sending SSH2_FXP_INIT

どうやら、perlでのsftpは、最近 Net::SFTP::Foreign らしい。
Net::SFTP::Foreign のdocumentにもそれらしく記載されています。

http://search.cpan.org/perldoc?Net%3A%3ASFTP%3A%3AForeign

「rating 見ましょう」という話ですね

#!/usr/local/bin/perl
use strict;
use utf8;
use Net::SFTP::Foreign;
use Data::Dumper;

main();

sub main {
    my $sftp = Net::SFTP::Foreign->new('ないしょ',
				       user=>'ないしょ',
				       password=>'ないしょ',
				       more=>[-o=>'StrictHostKeyChecking no',
					      '-v']);
    $sftp->put('foo.txt','/www/foo.txt');
}