1SCP(3)                User Contributed Perl Documentation               SCP(3)
2
3
4

NAME

6       Net::SCP - Perl extension for secure copy protocol
7

SYNOPSIS

9         #procedural interface
10         use Net::SCP qw(scp iscp);
11         scp($source, $destination);
12         iscp($source, $destination); #shows command, asks for confirmation, and
13                                      #allows user to type a password on tty
14
15         #OO interface
16         $scp = Net::SCP->new( "hostname", "username" );
17         #with named params
18         $scp = Net::SCP->new( { "host"=>$hostname, "user"=>$username } );
19         $scp->get("filename") or die $scp->{errstr};
20         $scp->put("filename") or die $scp->{errstr};
21         #tmtowtdi
22         $scp = new Net::SCP;
23         $scp->scp($source, $destination);
24
25         #Net::FTP-style
26         $scp = Net::SCP->new("hostname");
27         $scp->login("user");
28         $scp->cwd("/dir");
29         $scp->size("file");
30         $scp->get("file");
31

DESCRIPTION

33       Simple wrappers around ssh and scp commands.
34

SUBROUTINES

36       scp SOURCE, DESTINATION
37           Can be called either as a subroutine or a method; however, the
38           subroutine interface is depriciated.
39
40           Calls scp in batch mode, with the -B -p -q and -r options.  Returns
41           false upon error, with a text error message accessable in
42           $scp->{errstr}.
43
44           Returns false and sets the errstr attribute if there is an error.
45
46       iscp SOURCE, DESTINATION
47           Can be called either as a subroutine or a method; however, the
48           subroutine interface is depriciated.
49
50           Prints the scp command to be execute, waits for the user to
51           confirm, and (optionally) executes scp, with the -p and -r flags.
52
53           Returns false and sets the errstr attribute if there is an error.
54

METHODS

56       new HOSTNAME [ USER ] | HASHREF
57           This is the constructor for a new Net::SCP object.  You must
58           specify a hostname, and may optionally provide a user.
59           Alternatively, you may pass a hashref of named params, with the
60           following keys:
61
62               host - hostname
63               user - username
64               interactive - bool
65               cwd - current working directory on remote server
66
67       login [USER]
68           Compatibility method.  Optionally sets the user.
69
70       cwd CWD
71           Sets the cwd (used for a subsequent get or put request without a
72           full pathname).
73
74       get REMOTE_FILE [, LOCAL_FILE]
75           Uses scp to transfer REMOTE_FILE from the remote host.  If a local
76           filename is omitted, uses the basename of the remote file.
77
78       mkdir DIRECTORY
79           Makes a directory on the remote server.  Returns false and sets the
80           errstr attribute on errors.
81
82           (Implementation note: An ssh connection is established to the
83           remote machine and '/bin/mkdir -p' is used to create the
84           directory.)
85
86       size FILE
87           Returns the size in bytes for the given file as stored on the
88           remote server.  Returns 0 on error, and sets the errstr attribute.
89           In the case of an actual zero-length file on the remote server, the
90           special value '0e0' is returned, which evaluates to zero when used
91           as a number, but is true.
92
93           (Implementation note: An ssh connection is established to the
94           remote machine and wc is used to determine the file size.)
95
96       put LOCAL_FILE [, REMOTE_FILE]
97           Uses scp to trasnfer LOCAL_FILE to the remote host.  If a remote
98           filename is omitted, uses the basename of the local file.
99
100       binary
101           Compatibility method: does nothing; returns true.
102
103       quit
104           Compatibility method: does nothing; returns true.
105

FREQUENTLY ASKED QUESTIONS

107       Q: How do you supply a password to connect with ssh within a perl
108       script using the Net::SSH module?
109
110       A: You don't (at least not with this module).  Use RSA or DSA keys.
111       See the
112          quick help in the next section and the ssh-keygen(1) manpage.
113
114       A #2: See Net::SCP::Expect instead.
115
116       Q: My script is "leaking" scp processes.
117
118       A: See "How do I avoid zombies on a Unix system" in perlfaq8,
119       IPC::Open2, IPC::Open3 and "waitpid" in perlfunc.
120

GENERATING AND USING SSH KEYS

122       1 Generate keys
123           Type:
124
125              ssh-keygen -t rsa
126
127           And do not enter a passphrase unless you wanted to be prompted for
128           one during file copying.
129
130           Here is what you will see:
131
132              $ ssh-keygen -t rsa
133              Generating public/private rsa key pair.
134              Enter file in which to save the key (/home/User/.ssh/id_rsa):
135              Enter passphrase (empty for no passphrase):
136
137              Enter same passphrase again:
138
139              Your identification has been saved in /home/User/.ssh/id_rsa.
140              Your public key has been saved in /home/User/.ssh/id_rsa.pub.
141              The key fingerprint is:
142              5a:cd:2b:0a:cd:d9:15:85:26:79:40:0c:55:2a:f4:23 User@JEFF-CPU
143
144       2 Copy public to machines you want to upload to
145           "id_rsa.pub" is your public key. Copy it to "~/.ssh" on target
146           machine.
147
148           Put a copy of the public key file on each machine you want to log
149           into.  Name the copy "authorized_keys" (some implementations name
150           this file "authorized_keys2")
151
152           Then type:
153
154                chmod 600 authorized_keys
155
156           Then make sure your home dir on the remote machine is not group or
157           world writeable.
158

AUTHORS

160       Could really use a maintainer with enough time to at least review and
161       apply patches more patches.  Or the module should just be deprecated in
162       favor of Net::SFTP::Expect or Net::SFTP::Foreign and made into a simple
163       compatiblity wrapper.
164
165       Ivan Kohler <ivan-netscp_pod@420.am>
166
167       Major updates Anthony Deaver <bishop@projectmagnus.org>
168
169       Thanks to Jon Gunnip <jon@soundbite.com> for fixing a bug with size().
170
171       Patch for the mkdir method by Anthony Awtrey <tony@awtrey.com>.
172
173       Thanks to terrence brannon <tbone@directsynergy.com> for the
174       documentation in the GENERATING AND USING SSH KEYS section.
175
177       Copyright (c) 2000 Ivan Kohler Copyright (c) 2007 Freeside Internet
178       Services, Inc.  All rights reserved.  This program is free software;
179       you can redistribute it and/or modify it under the same terms as Perl
180       itself.
181

BUGS

183       Still has no-OO cruft.
184
185       In order to work around some problems with commercial SSH2, if the
186       source file is on the local system, and is not a directory, the -r flag
187       is omitted.  It's probably better just to use OpenSSH
188       <http://www.openssh.com/> which is the de-facto standard these days
189       anyway.
190
191       The Net::FTP-style OO stuff is kinda lame.  And incomplete.
192
193       iscp doesnt expect you to be logging into the box that you are copying
194       to for the first time. so it's completely clueless about how to handle
195       the whole 'add this file to known hosts' message so it just hangs after
196       the user hits y.  (Thanks to John L. Utz III).  To avoid this, SSH to
197       the box once first.
198

SEE ALSO

200       For a perl implementation that does not require the system scp command,
201       see Net::SFTP instead.
202
203       For a wrapper version that allows you to use passwords, see
204       Net::SCP::Expect instead.
205
206       For a wrapper version of the newer SFTP protocol, see
207       Net::SFTP::Foreign instead.
208
209       Net::SSH, Net::SSH::Perl, Net::SSH::Expect, Net::SSH2, IPC::PerlSSH
210
211       scp(1), ssh(1), IO::File, IPC::Open2, IPC::Open3
212
213
214
215perl v5.32.1                      2021-01-27                            SCP(3)
Impressum