Net-SCP-0.08/0000755000175000017500000000000010710473504011267 5ustar ivanivanNet-SCP-0.08/Makefile.PL0000655000175000017500000000064007170371124013244 0ustar ivanivanuse ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( 'NAME' => 'Net::SCP', 'VERSION_FROM' => 'SCP.pm', # finds $VERSION 'PREREQ_PM' => { 'Net::SSH' => 0, 'String::ShellQuote' => 0, 'IO::Handle' => 0 }, ); Net-SCP-0.08/Changes0000655000175000017500000000331310710473432012564 0ustar ivanivanRevision history for Perl extension Net::SCP. 0.08 Fri Oct 26 16:23:30 PDT 2007 - Fix mkdir error message and extraneous warning, patch from Ofer Nave , thanks! - Remove quit from the SYNOPSIS, and add a no-op quit method anyway, for the sake of being an easier Net::FTP replacement. Thanks to Zak Zebrowski , tvilliers at Lastminute.com, Joe Smith and others for the pointer. Closes: CPAN #14803 - Fix unused "interactive" option in new method. Huh. Thanks to John L. Utz III . - Document need to log into boxes once first. - Add links to the more current stuff on CPAN. - Patch to prevent an active CHLD reaper from picking up our ssh process from from peterspeltz@yahoo.com. Closes: CPAN#19189 - Documentation patch about ssh-keygen from terrence brannon 0.07 Wed Mar 3 00:38:25 2004 - get and put methods use OO-style scp to avoid clobbering errstr, thanks to paguerlais@airfrance.fr - remove extraneous warn 0.06 Sat Apr 13 15:16:56 2002 - mkdir method added by Anthony Awtrey 0.05 Wed Oct 24 03:49:06 2001 - documentation update 0.04 Wed Feb 07 10:26:11 2000 - fixed silly scp problem, thanks to Dan McCormick 0.03 Mon Feb 05 07:02:34 2000 - fixed documentation errors and iscp/issh problems from merge 0.02 Fri Dec 08 16:03:00 2000 - applied patch from Anthony Deaver; cleanups & better error checking - applied patch from Jon Gunnip; fixes size() method 0.01 Tue Aug 8 20:34:28 2000 - original version; created by h2xs 1.19 Net-SCP-0.08/SCP.pm0000655000175000017500000002534110710473326012263 0ustar ivanivanpackage Net::SCP; use strict; use vars qw($VERSION @ISA @EXPORT_OK $scp $DEBUG); use Exporter; use Carp; use File::Basename; use String::ShellQuote; use IO::Handle; use Net::SSH qw(sshopen3); use IPC::Open3; @ISA = qw(Exporter); @EXPORT_OK = qw( scp iscp ); $VERSION = '0.08'; $scp = "scp"; $DEBUG = 0; =head1 NAME Net::SCP - Perl extension for secure copy protocol =head1 SYNOPSIS #procedural interface use Net::SCP qw(scp iscp); scp($source, $destination); iscp($source, $destination); #shows command, asks for confirmation, and #allows user to type a password on tty #OO interface $scp = Net::SCP->new( "hostname", "username" ); #with named params $scp = Net::SCP->new( { "host"=>$hostname, "user"=>$username } ); $scp->get("filename") or die $scp->{errstr}; $scp->put("filename") or die $scp->{errstr}; #tmtowtdi $scp = new Net::SCP; $scp->scp($source, $destination); #Net::FTP-style $scp = Net::SCP->new("hostname"); $scp->login("user"); $scp->cwd("/dir"); $scp->size("file"); $scp->get("file"); =head1 DESCRIPTION Simple wrappers around ssh and scp commands. =head1 SUBROUTINES =over 4 =item scp SOURCE, DESTINATION Can be called either as a subroutine or a method; however, the subroutine interface is depriciated. Calls scp in batch mode, with the B<-B> B<-p> B<-q> and B<-r> options. Returns false upon error, with a text error message accessable in $scp->{errstr}. Returns false and sets the B attribute if there is an error. =cut sub scp { my $self = ref($_[0]) ? shift : {}; my($src, $dest, $interact) = @_; my $flags = '-p'; $flags .= 'r' unless &_islocal($src) && ! -d $src; my @cmd; if ( ( defined($interact) && $interact ) || ( defined($self->{interactive}) && $self->{interactive} ) ) { @cmd = ( $scp, $flags, $src, $dest ); print join(' ', @cmd), "\n"; unless ( &_yesno ) { $self->{errstr} = "User declined"; return 0; } } else { $flags .= 'qB'; @cmd = ( $scp, $flags, $src, $dest ); } my($reader, $writer, $error ) = ( new IO::Handle, new IO::Handle, new IO::Handle ); $writer->autoflush(1);# $error->autoflush(1); local $SIG{CHLD} = 'DEFAULT'; my $pid = open3($writer, $reader, $error, @cmd ); waitpid $pid, 0; if ( $? >> 8 ) { my $errstr = join('', <$error>); #chomp(my $errstr = <$error>); $self->{errstr} = $errstr; 0; } else { 1; } } =item iscp SOURCE, DESTINATION Can be called either as a subroutine or a method; however, the subroutine interface is depriciated. Prints the scp command to be execute, waits for the user to confirm, and (optionally) executes scp, with the B<-p> and B<-r> flags. Returns false and sets the B attribute if there is an error. =cut sub iscp { if ( ref($_[0]) ) { my $self = shift; $self->{'interactive'} = 1; $self->scp(@_); } else { scp(@_, 1); } } sub _yesno { print "Proceed [y/N]:"; my $x = scalar(); $x =~ /^y/i; } sub _islocal { shift !~ /^[^:]+:/ } =back =head1 METHODS =over 4 =item new HOSTNAME [ USER ] | HASHREF This is the constructor for a new Net::SCP object. You must specify a hostname, and may optionally provide a user. Alternatively, you may pass a hashref of named params, with the following keys: host - hostname user - username interactive - bool cwd - current working directory on remote server =cut sub new { my $proto = shift; my $class = ref($proto) || $proto; my $self; if ( ref($_[0]) ) { $self = shift; } else { $self = { 'host' => shift, 'user' => ( scalar(@_) ? shift : '' ), 'interactive' => 0, 'cwd' => '', }; } bless($self, $class); } =item login [USER] Compatibility method. Optionally sets the user. =cut sub login { my($self, $user) = @_; $self->{'user'} = $user if $user; } =item cwd CWD Sets the cwd (used for a subsequent get or put request without a full pathname). =cut sub cwd { my($self, $cwd) = @_; $self->{'cwd'} = $cwd || '/'; } =item get REMOTE_FILE [, LOCAL_FILE] Uses scp to transfer REMOTE_FILE from the remote host. If a local filename is omitted, uses the basename of the remote file. =cut sub get { my($self, $remote, $local) = @_; $remote = $self->{'cwd'}. "/$remote" if $self->{'cwd'} && $remote !~ /^\//; $local ||= basename($remote); my $source = $self->{'host'}. ":$remote"; $source = $self->{'user'}. '@'. $source if $self->{'user'}; $self->scp($source,$local); } =item mkdir DIRECTORY Makes a directory on the remote server. Returns false and sets the B attribute on errors. (Implementation note: An ssh connection is established to the remote machine and '/bin/mkdir B<-p>' is used to create the directory.) =cut sub mkdir { my($self, $directory) = @_; $directory = $self->{'cwd'}. "/$directory" if $self->{'cwd'} && $directory !~ /^\//; my $host = $self->{'host'}; $host = $self->{'user'}. '@'. $host if $self->{'user'}; my($reader, $writer, $error ) = ( new IO::Handle, new IO::Handle, new IO::Handle ); $writer->autoflush(1); my $pid = sshopen3( $host, $writer, $reader, $error, '/bin/mkdir', '-p ', shell_quote($directory) ); waitpid $pid, 0; if ( $? >> 8 ) { chomp(my $errstr = <$error> || ''); $self->{errstr} = $errstr || "mkdir exited with status ". ($?>>8); return 0; } 1; } =item size FILE Returns the size in bytes for the given file as stored on the remote server. Returns 0 on error, and sets the B attribute. In the case of an actual zero-length file on the remote server, the special value '0e0' is returned, which evaluates to zero when used as a number, but is true. (Implementation note: An ssh connection is established to the remote machine and wc is used to determine the file size.) =cut sub size { my($self, $file) = @_; $file = $self->{'cwd'}. "/$file" if $self->{'cwd'} && $file !~ /^\//; my $host = $self->{'host'}; $host = $self->{'user'}. '@'. $host if $self->{'user'}; my($reader, $writer, $error ) = ( new IO::Handle, new IO::Handle, new IO::Handle ); $writer->autoflush(1); #sshopen2($host, $reader, $writer, 'wc', '-c ', shell_quote($file) ); my $pid = sshopen3($host, $writer, $reader, $error, 'wc', '-c ', shell_quote($file) ); waitpid $pid, 0; if ( $? >> 8 ) { chomp(my $errstr = <$error>); $self->{errstr} = $errstr || "wc exited with status ". $?>>8; 0; } else { chomp( my $size = <$reader> || 0 ); if ( $size =~ /^\s*(\d+)/ ) { $1 ? $1 : '0e0'; } else { $self->{errstr} = "unparsable output from remote wc: $size"; 0; } } } =item put LOCAL_FILE [, REMOTE_FILE] Uses scp to trasnfer LOCAL_FILE to the remote host. If a remote filename is omitted, uses the basename of the local file. =cut sub put { my($self, $local, $remote) = @_; $remote ||= basename($local); $remote = $self->{'cwd'}. "/$remote" if $self->{'cwd'} && $remote !~ /^\//; my $dest = $self->{'host'}. ":$remote"; $dest = $self->{'user'}. '@'. $dest if $self->{'user'}; warn "scp $local $dest\n" if $DEBUG; $self->scp($local, $dest); } =item binary Compatibility method: does nothing; returns true. =cut sub binary { 1; } =item quit Compatibility method: does nothing; returns true. =cut sub quit { 1; } =back =head1 FREQUENTLY ASKED QUESTIONS Q: How do you supply a password to connect with ssh within a perl script using the Net::SSH module? A: You don't (at least not with this module). Use RSA or DSA keys. See the quick help in the next section and the ssh-keygen(1) manpage. A #2: See L instead. Q: My script is "leaking" scp processes. A: See L, L, L and L. =head1 GENERATING AND USING SSH KEYS =over 4 =item 1 Generate keys Type: ssh-keygen -t rsa And do not enter a passphrase unless you wanted to be prompted for one during file copying. Here is what you will see: $ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/User/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/User/.ssh/id_rsa. Your public key has been saved in /home/User/.ssh/id_rsa.pub. The key fingerprint is: 5a:cd:2b:0a:cd:d9:15:85:26:79:40:0c:55:2a:f4:23 User@JEFF-CPU =item 2 Copy public to machines you want to upload to C is your public key. Copy it to C<~/.ssh> on target machine. Put a copy of the public key file on each machine you want to log into. Name the copy C (some implementations name this file C) Then type: chmod 600 authorized_keys Then make sure your home dir on the remote machine is not group or world writeable. =back =head1 AUTHORS Could really use a maintainer with enough time to at least review and apply patches more patches. Or the module should just be deprecated in favor of Net::SFTP::Expect or Net::SFTP::Foreign and made into a simple compatiblity wrapper. Ivan Kohler Major updates Anthony Deaver Thanks to Jon Gunnip for fixing a bug with size(). Patch for the mkdir method by Anthony Awtrey . Thanks to terrence brannon for the documentation in the GENERATING AND USING SSH KEYS section. =head1 COPYRIGHT Copyright (c) 2000 Ivan Kohler Copyright (c) 2007 Freeside Internet Services, Inc. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 BUGS Still has no-OO cruft. In order to work around some problems with commercial SSH2, if the source file is on the local system, and is not a directory, the B<-r> flag is omitted. It's probably better just to use OpenSSH which is the de-facto standard these days anyway. The Net::FTP-style OO stuff is kinda lame. And incomplete. iscp doesnt expect you to be logging into the box that you are copying to for the first time. so it's completely clueless about how to handle the whole 'add this file to known hosts' message so it just hangs after the user hits y. (Thanks to John L. Utz III). To avoid this, SSH to the box once first. =head1 SEE ALSO For a perl implementation that does not require the system B command, see L instead. For a wrapper version that allows you to use passwords, see L instead. For a wrapper version of the newer SFTP protocol, see L instead. L, L, L, L, L scp(1), ssh(1), L, L, L =cut 1; Net-SCP-0.08/test.pl0000655000175000017500000000121507170371124012605 0ustar ivanivan# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl test.pl' ######################### We start with some black magic to print on failure. # Change 1..1 below to 1..last_test_to_print . # (It may become useful if the test is moved to ./t subdirectory.) BEGIN { $| = 1; print "1..1\n"; } END {print "not ok 1\n" unless $loaded;} use Net::SCP; $loaded = 1; print "ok 1\n"; ######################### End of black magic. # Insert your test code below (better if it prints "ok 13" # (correspondingly "not ok 13") depending on the success of chunk 13 # of the test code): Net-SCP-0.08/README0000655000175000017500000000177507456127230012170 0ustar ivanivanNet::SCP Copyright (c) 2000 Ivan Kohler. Copyright (c) 2000 Silicon Interactive Software Design. Copyright (c) 2000 Freeside Internet Services, LLC All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. This module implements a Perl interface to scp. To install: perl Makefile.PL make make test # nothing substantial yet make install Documentation will then be available via `man Net:SCP' or `perldoc Net::SCP' Anonymous CVS access is available: $ export CVSROOT=":pserver:anonymous@cleanwhisker.402.am:/home/cvs/cvsroot" $ cvs login (Logging in to anonymous@cleanwhisker.420.am) CVS password: anonymous $ cvs checkout Net-SCP as well as . A mailing list for users and developers is available. Send a blank message to to subscribe. Ivan Kohler $Id: README,v 1.4 2002-04-13 22:18:00 ivan Exp $ Net-SCP-0.08/MANIFEST.SKIP0000655000175000017500000000000507170371124013163 0ustar ivanivanCVS/ Net-SCP-0.08/MANIFEST0000655000175000017500000000010107170371124012413 0ustar ivanivanChanges MANIFEST MANIFEST.SKIP Makefile.PL SCP.pm test.pl README