2011-05-12 3 views
3

Net :: SSH2의 scp_put 메서드를 사용하여 Windows 상자에서 유닉스 서버의 홈 디렉토리에 하나의 파일을 저장합니다. Strawberry Perl 5.12 (휴대용 버전)를 사용하고 있습니다. libssh2 1.2.5 바이너리를 설치 한 다음 cpan에서 Net :: SSH2를 설치했습니다.Perl Net :: SSH2 scp_put이 파일을 put 한 후 멈춤

sub uploadToHost{ 

my [email protected]_[0]; 
my [email protected]_[1]; 
my [email protected]_[2]; 
my [email protected]_[3]; 
my [email protected]_[4]; 

#makes a new SSH2 object 
my $ssh=Net::SSH2->new() or die "couldn't make SSH object\n"; 

#prints proper error messages 
$ssh->debug(1); 

#nothing works unless I explicitly set blocking on 
$ssh->blocking(1); 
print "made SSH object\n"; 

#connect to host; this always works 
$ssh->connect($host) or die "couldn't connect to host\n"; 
print "connected to host\n"; 

#authenticates with password 
$ssh->auth_password($user, $pass) or die "couldn't authenticate $user\n"; 
print "authenticated $user\n"; 

#this is the tricky bit that hangs 
$ssh->scp_put($file, $remotelocation") or die "couldn't put file in $remotelocation\n"; 
print "uploaded $file successfully\n"; 

$ssh->disconnect or die "couldn't disconnect\n"; 

} #ends sub 

출력 (익명 위해 편집) :

만든 SSH 개체 \ n

연결 \ 호스트 N

인증 \ n을

여기 내 코드입니다

libssh2_scp_send_ex (ss-> 세션, 경로, 모드, 크기, mtime, atime) -> 0x377e61c \ 없음

순 :: SSH2 :: 채널 :: 읽기 (크기 = 1, 내선 = 0) \ n 그런 다음 영원히 중단

(> 하나 개의 테스트에서 40 분)과은에 필요 살해 당한다.

무엇이 이상한가요? 은 실제로 원격 서버에 파일을 scp합니다! 완료된 후에 만 ​​중단됩니다. StackOverflow 또는 다른 곳에서이 호기심 문제에 대한 참조를 찾을 수 없습니다.

누구나 나를 올바른 방향으로 가리킬 수 있습니다 1) 교수형에서 중지하거나 2) (이 해결 방법으로 몇 초 후에이 한 명령을 죽이는 타이머를 구현하는 파일을 scp하는 충분한 시간입니다 ?

감사합니다.

답변

0
'alarm.pl'당신이 어떻게 작동하는지 볼 수 있습니다 당신은이 예제를 저장하면, 행동하는로 프로세스를 자극하는 경보를()를 사용하여 시도 할 수 있습니다

:

use strict; 
use warnings; 
use 5.10.0; 

# pretend to be a slow process if run as 'alarm.pl s' 
if (@ARGV && $ARGV[0] eq 's') { 
    sleep(30); 
    exit(); 
} 

# Otherwise set an alarm, then run myself with 's' 
eval { 
    local $SIG{ALRM} = sub {die "alarmed\n"}; 
    alarm(5); 
    system("perl alarm.pl s"); 
}; 
if ([email protected]) { 
    die [email protected] unless [email protected] eq "alarmed\n"; 
    say "Timed out slow process"; 
} 
else { 
    say "Slow process finished"; 
} 
0

사용 Net::SFTP::Foreign을 인터넷으로 :: SSH2 백엔드, Net::SFTP::Foreign::Backend::Net_SSH2 :

use Net::SFTP::Foreign; 

my $sftp = Net::SFTP::Foreign->new($host, user => $user, password => $password, backend => Net_SSH2); 
$sftp->die_on_error("Unable to connect to remote host"); 

$sftp->put($file, $remotelocation); 
$sftp->die_on_error("Unable to copy file"); 

그 중 하나가 작동하지 않는 경우, 당신은 (퍼티 프로젝트에서) 가용 스루풋을 사용하여 시도 할 수 있습니다 대신 인터넷 :: SSH2 백엔드.

-1

매달린 것 같지 않습니다. 정말 느립니다. 10 배는 느려야합니다. 파일이 거기에있는 것처럼 보이는 이유는 파일 전송이 완료되기 전에 파일을 할당하기 때문입니다. 이것은 예상치 못한 것은 아니지만 Perl은 프로그래머를 실망시키고 좌절시키는 새로운 방법을 매일 발견합니다. 때로는 Perl의 특이점을 해결하고 실제 작업을 수행하는 것과 같은 일을하는 10 가지의 약간 다른 방법을 배우는데 더 많은 시간을 할애한다고 생각합니다.

+0

5MB/s를 수행 할 수있는 링크에서 약 150kB/s 속도로 시작하지만 약 2MB의 데이터가 전송 된 후에는 약 5KB/s로 느려집니다. 따라서 실제로는 문자 그대로 1000x 느리게 실행됩니다. – MikeKulls