.\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "SCP 3pm" .TH SCP 3pm "2018-07-31" "perl v5.26.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Net::SCP \- Perl extension for secure copy protocol .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 5 \& #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"); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Simple wrappers around ssh and scp commands. .SH "SUBROUTINES" .IX Header "SUBROUTINES" .IP "scp \s-1SOURCE, DESTINATION\s0" 4 .IX Item "scp SOURCE, DESTINATION" Can be called either as a subroutine or a method; however, the subroutine interface is deprecated. .Sp Calls scp in batch mode, with the \fB\-B\fR \fB\-p\fR \fB\-q\fR and \fB\-r\fR options. Returns false upon error, with a text error message accessible in \&\f(CW$scp\fR\->{errstr}. .Sp Returns false and sets the \fBerrstr\fR attribute if there is an error. .IP "iscp \s-1SOURCE, DESTINATION\s0" 4 .IX Item "iscp SOURCE, DESTINATION" Can be called either as a subroutine or a method; however, the subroutine interface is deprecated. .Sp Prints the scp command to be execute, waits for the user to confirm, and (optionally) executes scp, with the \fB\-p\fR and \fB\-r\fR flags. .Sp Returns false and sets the \fBerrstr\fR attribute if there is an error. .SH "METHODS" .IX Header "METHODS" .IP "new \s-1HOSTNAME\s0 [ \s-1USER\s0 ] | \s-1HASHREF\s0" 4 .IX 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: .Sp .Vb 4 \& host \- hostname \& user \- username \& interactive \- bool \& cwd \- current working directory on remote server .Ve .IP "login [\s-1USER\s0]" 4 .IX Item "login [USER]" Compatibility method. Optionally sets the user. .IP "cwd \s-1CWD\s0" 4 .IX Item "cwd CWD" Sets the cwd (used for a subsequent get or put request without a full pathname). .IP "get \s-1REMOTE_FILE\s0 [, \s-1LOCAL_FILE\s0]" 4 .IX Item "get REMOTE_FILE [, LOCAL_FILE]" Uses scp to transfer \s-1REMOTE_FILE\s0 from the remote host. If a local filename is omitted, uses the basename of the remote file. .IP "mkdir \s-1DIRECTORY\s0" 4 .IX Item "mkdir DIRECTORY" Makes a directory on the remote server. Returns false and sets the \fBerrstr\fR attribute on errors. .Sp (Implementation note: An ssh connection is established to the remote machine and '/bin/mkdir \fB\-p\fR' is used to create the directory.) .IP "size \s-1FILE\s0" 4 .IX 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 \fBerrstr\fR 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. .Sp (Implementation note: An ssh connection is established to the remote machine and wc is used to determine the file size.) .IP "put \s-1LOCAL_FILE\s0 [, \s-1REMOTE_FILE\s0]" 4 .IX Item "put LOCAL_FILE [, REMOTE_FILE]" Uses scp to trasnfer \s-1LOCAL_FILE\s0 to the remote host. If a remote filename is omitted, uses the basename of the local file. .IP "binary" 4 .IX Item "binary" Compatibility method: does nothing; returns true. .IP "quit" 4 .IX Item "quit" Compatibility method: does nothing; returns true. .SH "FREQUENTLY ASKED QUESTIONS" .IX Header "FREQUENTLY ASKED QUESTIONS" Q: How do you supply a password to connect with ssh within a perl script using the Net::SSH module? .PP A: You don't (at least not with this module). Use \s-1RSA\s0 or \s-1DSA\s0 keys. See the quick help in the next section and the \fIssh\-keygen\fR\|(1) manpage. .PP A #2: See Net::SCP::Expect instead. .PP Q: My script is \*(L"leaking\*(R" scp processes. .PP A: See \*(L"How do I avoid zombies on a Unix system\*(R" in perlfaq8, IPC::Open2, IPC::Open3 and \*(L"waitpid\*(R" in perlfunc. .SH "GENERATING AND USING SSH KEYS" .IX Header "GENERATING AND USING SSH KEYS" .IP "1 Generate keys" 4 .IX Item "1 Generate keys" Type: .Sp .Vb 1 \& ssh\-keygen \-t rsa .Ve .Sp And do not enter a passphrase unless you wanted to be prompted for one during file copying. .Sp Here is what you will see: .Sp .Vb 4 \& $ 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 .Ve .IP "2 Copy public to machines you want to upload to" 4 .IX Item "2 Copy public to machines you want to upload to" \&\f(CW\*(C`id_rsa.pub\*(C'\fR is your public key. Copy it to \f(CW\*(C`~/.ssh\*(C'\fR on target machine. .Sp Put a copy of the public key file on each machine you want to log into. Name the copy \f(CW\*(C`authorized_keys\*(C'\fR (some implementations name this file \&\f(CW\*(C`authorized_keys2\*(C'\fR) .Sp Then type: .Sp .Vb 1 \& chmod 600 authorized_keys .Ve .Sp Then make sure your home dir on the remote machine is not group or world writeable. .SH "AUTHORS" .IX Header "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 compatibility wrapper. .PP Ivan Kohler .PP Major updates Anthony Deaver .PP Thanks to Jon Gunnip for fixing a bug with \fIsize()\fR. .PP Patch for the mkdir method by Anthony Awtrey . .PP Thanks to terrence brannon for the documentation in the \s-1GENERATING AND USING SSH KEYS\s0 section. .SH "COPYRIGHT" .IX Header "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. .SH "BUGS" .IX Header "BUGS" Still has no-OO cruft. .PP In order to work around some problems with commercial \s-1SSH2,\s0 if the source file is on the local system, and is not a directory, the \fB\-r\fR flag is omitted. It's probably better just to use OpenSSH which is the de-facto standard these days anyway. .PP The Net::FTP\-style \s-1OO\s0 stuff is kinda lame. And incomplete. .PP iscp doesn't 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 \s-1III\s0). To avoid this, \s-1SSH\s0 to the box once first. .SH "SEE ALSO" .IX Header "SEE ALSO" For a perl implementation that does not require the system \fBscp\fR command, see Net::SFTP instead. .PP For a wrapper version that allows you to use passwords, see Net::SCP::Expect instead. .PP For a wrapper version of the newer \s-1SFTP\s0 protocol, see Net::SFTP::Foreign instead. .PP Net::SSH, Net::SSH::Perl, Net::SSH::Expect, Net::SSH2, IPC::PerlSSH .PP \&\fIscp\fR\|(1), \fIssh\fR\|(1), IO::File, IPC::Open2, IPC::Open3