[Ssh-sftp-perl-users] Scp
Brought to you by:
dbrobins
From: Thierry C. <thi...@gm...> - 2008-10-08 08:35:08
|
Hello Greg and David, I see that there is a great work done with Net::SSH::Perl. I am happy since I was missing a functionnality, and I think that we can obtain result with the additions you have done. I want to be able to write something like (with an existing ssh object, login done) $ssh->scp_push($localfile,$remotefile); or $ssh->scp_get($remotefile,$localfile); It is possible with the module Net::SSH2 that David have written, and it is good enough for me, but ssh-agent si not supported with this module, and it is a key point. I didn't find the RFC where scp is described, so I had to analyze openssh and libssh2 in order to understand why I need to do. I have finally produce a protoype of what I want in Net/SSH/Perl/SSH2.pm sub scp_push { my $ssh = shift; my ($filesrc, $filedest) = @_; my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks) = stat($filesrc); open( my $filehandle, "$filesrc" ) or croak("Cannot open file $filesrc $!"); binmode ($filehandle); my @tmp=split("/",$filesrc); my $filesrc_invocation=$tmp[$#tmp]; my $cmd = "scp -v -t $filedest"; my $cmgr = $ssh->channel_mgr; my $channel = $ssh->_session_channel; $channel->open; $channel->register_handler( SSH2_MSG_CHANNEL_OPEN_CONFIRMATION, sub { my ( $channel, $packet ) = @_; $channel->{ssh}->debug("Sending command: $cmd"); my $r_packet = $channel->request_start( "exec", 0 ); $r_packet->put_str("$cmd"); $r_packet->send; if (defined $size) { $channel->send_data("C0644 $size $filesrc_invocation\n"); use constant CHUNK_SIZE => 8192; while (read ($filehandle, my $chunk, CHUNK_SIZE)){ $channel->send_data($chunk); $channel->drain_outgoing; $channel->{istate} = CHAN_INPUT_WAIT_DRAIN; } $channel->send_eof; $channel->{istate} = CHAN_INPUT_CLOSED; } } ); ..... You know what is next better than me ... ( $stdout, $stderr, $exit ); } As you can see, it is bad. My chunk_size is not large enough to have a good rate transfer. I didn't even know if there is some kind of negociation between client and server. I have write only a small small ;) subset of the scp protocol. It is a proof-of-concept prototype. My questions are: - I just see in the new 1.31 that there is a Subsystem generic call. Should I use it for this piece of code. - are you interested by this approach ? Is there something I don't see that is not allowing such functions to work ? - do you know where I can find a formal description of scp (I find openssh code not very documented) ? |