Expect(3pm)
๐ Expect(3pm) โ Net::SCP::Expect ๐
okay bestie, gather round โ this is the manual page for Net::SCP::Expect (it lives in section 3pm, the User Contributed Perl Documentation corner of the manual). It's a wrapper for scp that lets you hand over passwords via Expect, so you never have to sit there babysitting an interactive prompt like it's 2004. โจ
๐ธ NAME ๐ธ
Net::SCP::Expect โ a wrapper for scp that lets you pass passwords via Expect. periodt. ๐
๐ฆ SYNOPSIS ๐ฆ
Example 1 โ uses login method, longhand scp:
my $scpe = Net::SCP::Expect->new;
$scpe->login('user name', 'password');
$scpe->scp('file','host:/some/dir');
Example 2 โ uses constructor, shorthand scp:
my $scpe = Net::SCP::Expect->new(host=>'host', user=>'user', password=>'xxxx');
$scpe->scp('file','/some/dir'); # 'file' copied to 'host' at '/some/dir'
Example 3 โ copying from remote machine to local host:
my $scpe = Net::SCP::Expect->new(user=>'user',password=>'xxxx');
$scpe->scp('host:/some/dir/filename','newfilename');
Example 4 โ uses login method, longhand scp, IPv6 compatible:
my $scpe = Net::SCP::Expect->new;
$scpe->login('user name', 'password');
$scpe->scp('file','[ipv6-host]:/some/dir'); # <-- Important: scp() with explicit IPv6 host in to or from address must use square brackets
See the scp() method for more information on valid syntax. ๐
๐ PREREQUISITES ๐
- Expect 1.14. It may work with earlier versions, but it was tested with 1.14 (and now 1.15) only. so like, ymmv.
- Term::ReadPassword 0.01 is required if you wanna run the interactive test script. ๐ง
๐ DESCRIPTION ๐
So what is this? It's simply a wrapper around the scp call. The primary difference between this module and Net::SCP is that you may send a password programmatically, instead of being forced to deal with interactive sessions. no more typing your password into a prompt like a peasant, we love to see it. ๐
โจ USAGE โจ
Net::SCP::Expect->new(option=>val, ...)
Creates a new object and optionally takes a series of options (peep "OPTIONS" below ๐). All "OBJECT METHODS" apply to this constructor too.
๐ OBJECT METHODS ๐
auto_yes
Set this to 1 if you want to automatically pass a 'yes' string to any yes or no questions that you may encounter before actually being asked for a password, e.g. "Are you sure you want to continue connecting (yes/no)?" for first time connections, etc. the way it just handles the small talk for you. ๐
error_handler(sub ref)
This sets up an error handler to catch any problems with a call to 'scp()'. If you do not define an error handler, then a simple 'croak()' call will occur, with the last line sent to the terminal added as part of the error message.
Heads up: the method will immediately return with a void value after your error handler has been called.
host(host)
Sets the host for the current object. ๐
login(login, password)
If the login and password are not passed as options to the constructor, they must be passed with this method (or set individually โ see 'user' and 'password' methods). If they were already set, this method will overwrite them with the new values. Password will not be changed if only one argument is passed (user). โ ๏ธ
password(password)
Sets the password for the current user, or the passphrase for the identify file if identity_file option is specified in the constructor. ๐
user(user)
Sets the user for the current object. ๐ซถ
scp()
Copies the file from source to destination. If no host is specified, you will be using 'scp' as an expensive form of 'cp'. ๐ญ iconic honestly.
There are several valid ways to use this method ๐
Local to Remote
scp(source, user@host:destination);
scp(source, user@[ipv6-host]:destination); # Same as previous, with
IPv6 host
scp(source, host:destination); # User already defined
scp(source, [ipv6-host]:destination); # Same as previous, with IPv6 host
scp(source, :destination); # User and host already defined
scp(source, destination); # Same as previous
scp(source); # Same as previous; destination will use base name of
source
Remote to Local
scp(user@host:source, destination);
scp(user@[ipv6-host]:source, destination); # Same as previous, with IPv6
host
scp(host:source, destination);
scp([ipv6-host]:source, destination); # Same as previous, with IPv6 host
scp(:source, destination);
๐ OPTIONS ๐
auto_quoteโ Auto-encapsulate all option values andscpfrom/to arguments in single-quotes to insure that special characters, such as spaces in file names, do not cause inadvertant shell exceptions. Default is enabled. Note: Be aware that this feature may break backward compatibility with scripts that manually quoted input arguments to work around unquoted argument limitations in 0.12 or earlier of this module; in such cases, try disabling it or update your script to take advantage of theauto_quotefeature. ๐auto_yesโ Set this to1if you want to automatically pass a'yes'string to any yes or no questions that you may encounter before actually being asked for a password, e.g."Are you sure you want to continue connecting (yes/no)?"for first time connections, etc.cipherโ Selects the cipher to use for encrypting the data transfer. ๐compressโ Compression enable. Passes the-Cflag tossh(1)to enable compression.force_ipv4โ Forcesscpto use IPv4 addresses only.force_ipv6โ Forcesscpto use IPv6 addresses only.hostโ Specify the host name. This is now useful for both local-to-remote and remote-to-local transfers. For IPv6 addresses, either regular or square-bracket encapsulated host are allowed (since command-linescpnormally expects IPv6 addresses to be encapsulated in square brackets). ๐identity_fileโ Specify the identify file to use. ๐๏ธno_checkโ Set this to1if you want to turn off error checking. Use this if you're absolutely positive you won't encounter any errors and you want to speed up yourscpcalls โ up to 2 seconds per call (based on the defaults). โกoptionโ Specify options from the config file. This is the equivalent of-o.passwordโ The password for the given login. If not specified, thenidentity_filemust be specified or an error will occur on login. If bothidentity_fileandpasswordare specified, the password will be treated as the passphrase for the identity file. ๐portโ Use the specified port.preserveโ Preserves modification times, access times, and modes from the original file.protocolโ Specify the ssh protocol to use forscp. The default isundef, which simply meansscpwill use whatever it normally would use.recursiveโ Set to1if you want to recursively copy entire directories. ๐scp_pathโ The path for thescpbinary to use, i.e.:/usr/bin/scp, defaults to use the firstscpon your$PATHvariable.subsystemโ Specify a subsystem to invoke on the remote system. This option is only valid withssh2andopensshafaik.terminatorโ Set the string terminator that is attached to the end of the password. The default is a newline. ๐timeoutโ Sets the timeout value for yourscpoperation. The default is 10 seconds. โฐtimeout_autoโ Sets the timeout for the'auto_yes'option. I separated this from the standard timeout because generally you won't need nearly as much time as you would for a standard timeout, otherwise your script will drag considerably. The default is 1 second (which should be plenty).timeout_errโ Sets the timeout for the additional error checking that the module does. Because errors come back almost instantaneously, I thought it best to make this a separate option for the same reasons as the'timeout_auto'option above. The default is'undef'.- Setting it to any integer value means that your program will exit after that many seconds whether or not the operation has completed. Caveat programmor. ๐
userโ The login name you wish to use.verboseโ Set to1if you want verbose output sent toSTDOUT. Note that this disables some error checking (alano_check) because the verbose output could otherwise be picked up by expect itself.
๐ง NOTES ๐ง
- The
-qoption (disable progress meter) is automatically passed toscp. ๐ - The
-Boption may NOT be set. If you don't plan to send passwords or use identity files (with passphrases), consider usingNet::SCPinstead. - In the event a new version of
Net::SSH::Perlis released that supportsscp, I recommend using that instead. Why? First, it should be a more secure way to performscp. Second, this module is not the fastest, even with error checking turned off. Both reasons have to do with TTY interaction. ๐ฎโ๐จ - Also, please see the
Net::SFTPmodule from Dave Rolsky. If this suits your needs, use it instead. ๐
๐ FUTURE PLANS ๐
There are a few options I haven't implemented. If you really want to see them added, let me know and I'll see what I can do.
- Add exception handling tests to the interactive test suite.
๐ KNOWN ISSUES ๐
- At least one user has reported warnings related to POD parsing with Perl 5.00503. These can be safely ignored. They do not appear in Perl 5.6 or later.
- Probably not thread safe. See RT bug #7567 from Adam Ruck.
๐ THANKS ๐
- Thanks to Roland Giersig (and Austin Schutz) for the Expect module. Very handy. ๐ซถ
- Thanks also go out to all those who have submitted bug reports and/or patches. See the
CHANGESfile for specifics.
๐ LICENSE ๐
Net::SCP::Expect is licensed under the same terms as Perl itself. โจ
๐ COPYRIGHT ๐
2005-2008 Eric Rybski <rybskej@yahoo.com>, 2003-2004 Daniel J. Berger.
๐ธ CURRENT AUTHOR AND MAINTAINER ๐ธ
Eric Rybski <rybskej@yahoo.com>. Please send all module inquries to me. ๐
โญ ORIGINAL AUTHOR โญ
Daniel Berger
djberg96 at yahoo dot com
imperator on IRC
๐ฅ SEE ALSO ๐ฅ
Net::SCP, Net::SFTP, Net::SSH::Perl, Net::SSH2
and that's the whole page bestie, we ate and left no crumbs ๐ โ this was Expect(3pm) from perl v5.32.0, dated 2021-01-06, part of the User Contributed Perl Documentation. go forth and scp responsibly ๐
โจ
๐ฆ where this page comes from
- debian bookworm: libnet-scp-expect-perl 0.16-2.1 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libnet-scp-expect-perl 0.16-2.1 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libnet-scp-expect-perl 0.16-2.1 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libnet-scp-expect-perl 0.16-2.1 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libnet-scp-expect-perl 0.16-2.1 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libnet-scp-expect-perl 0.16-2.1 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms