SCP(3pm) | User Contributed Perl Documentation | SCP(3pm) |
Net::SCP - Perl extension for secure copy protocol
#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");
Simple wrappers around ssh and scp commands.
Calls scp in batch mode, with the -B -p -q and -r options. Returns false upon error, with a text error message accessible in $scp->{errstr}.
Returns false and sets the errstr attribute if there is an error.
Prints the scp command to be execute, waits for the user to confirm, and (optionally) executes scp, with the -p and -r flags.
Returns false and sets the errstr attribute if there is an error.
host - hostname user - username interactive - bool cwd - current working directory on remote server
(Implementation note: An ssh connection is established to the remote machine and '/bin/mkdir -p' is used to create the directory.)
(Implementation note: An ssh connection is established to the remote machine and wc is used to determine the file size.)
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 Net::SCP::Expect instead.
Q: My script is "leaking" scp processes.
A: See "How do I avoid zombies on a Unix system" in perlfaq8, IPC::Open2, IPC::Open3 and "waitpid" in perlfunc.
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
Put a copy of the public key file on each machine you want to log into. Name the copy "authorized_keys" (some implementations name this file "authorized_keys2")
Then type:
chmod 600 authorized_keys
Then make sure your home dir on the remote machine is not group or world writeable.
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.
Ivan Kohler <ivan-netscp_pod@420.am>
Major updates Anthony Deaver <bishop@projectmagnus.org>
Thanks to Jon Gunnip <jon@soundbite.com> for fixing a bug with size().
Patch for the mkdir method by Anthony Awtrey <tony@awtrey.com>.
Thanks to terrence brannon <tbone@directsynergy.com> for the documentation in the GENERATING AND USING SSH KEYS section.
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.
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 -r flag is omitted. It's probably better just to use OpenSSH <http://www.openssh.com/> which is the de-facto standard these days anyway.
The Net::FTP-style OO stuff is kinda lame. And incomplete.
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 III). To avoid this, SSH to the box once first.
For a perl implementation that does not require the system scp command, see Net::SFTP instead.
For a wrapper version that allows you to use passwords, see Net::SCP::Expect instead.
For a wrapper version of the newer SFTP protocol, see Net::SFTP::Foreign instead.
Net::SSH, Net::SSH::Perl, Net::SSH::Expect, Net::SSH2, IPC::PerlSSH
scp(1), ssh(1), IO::File, IPC::Open2, IPC::Open3
2018-07-31 | perl v5.26.2 |