man Net::SCP::Expect () - Wrapper for scp that allows passwords via Expect.

NAME

Net::SCP::Expect - Wrapper for scp that allows passwords via Expect.

SYNOPSIS

Example 1 - uses login method, longhand scp:

CWmy $scpe = Net::SCP::Expect->new;

CW$scpe->login('user name', 'password');

CW$scpe->scp('file','host:/some/dir');

Example 2 - uses constructor, shorthand scp:

CWmy $scpe = Net::SCP::Expect->new(host=>'host', user=>'user', password=>'xxxx');

CW$scpe->scp('file','/some/dir'); # 'file' copied to 'host' at '/some/dir'

Example 3 - Copying from remote machine to local host

CWmy $scpe = Net::SCP::Expect->new(user=>'user',password=>'xxxx');

CW$scpe->scp('host:/some/dir/filename','newfilename');

See the BIscp() method for more information on valid syntax.

PREREQUISITES

Expect 1.14. May work with earlier versions, but was tested with 1.14 (and now 1.15) only.

Term::ReadPassword 0.01 is required if you want to execute the interactive test script.

DESCRIPTION

This module is 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.

USAGE

Net::SCP::Expect->new(option=>val,...)

Creates a new object and optionally takes a series of options (see OPTIONS below).

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.

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.

I highly recommend you forcibly terminate your program somehow within your handler (via die, croak, exit, etc), otherwise your program may hang, as it sits there waiting for terminal input.

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(password)

Sets the password for the current user

user(user)

Sets the user for the current object

BIscp()

Copies the file from source to destination. If no host is specified, you will be using 'scp' as an expensive form of 'cp'.

There are several valid ways to use this method

LOCAL TO REMOTE

scp(source, user@host:destination);

scp(source, host:destination); # User already defined

scp(source, :destination); # User and host already defined

scp(source, destination); # Same as previous

REMOTE TO LOCAL

scp(user@host:source, destination);

scp(host:source, destination);

scp(:source, destination);

OPTIONS

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.

cipher - Selects the cipher to use for encrypting the data transfer.

host - Specify the host name. This is now useful for both local-to-remote and remote-to-local transfers.

identity_file - Specify the identify file to use.

no_check - Set this to 1 if 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 your scp calls - 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.

port - Use the specified port.

preserve - Preserves modification times, access times, and modes from the original file.

protocol - Specify the ssh protocol to use for scp. The default is undef, which simply means scp will use whatever it normally would use.

recursive - Set to 1 if you want to recursively copy entire directories.

subsystem - Specify a subsystem to invoke on the remote system. This option is only valid with ssh2 and openssh afaik.

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 your scp operation. 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 to 1 if you want verbose output sent to STDOUT. Note that this disables some error checking (ala no_check) because the verbose output could otherwise be picked up by expect itself.

NOTES

The -q option (disable progress meter) is automatically passed to scp.

The -B option may NOT be set. If you don't want to send passwords, I recommend using Net::SCP instead.

In the event that Dave Rolsky releases a version of Net::SSH::Perl that supports scp, I recommend using that instead. Why? First, it will be a more secure way to perform scp. Second, this module is not fast, even with error checking turned off. Both reasons have to do with TTY interaction.

Also, please see the Net::SFTP module 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.

KNOWN BUGS

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.

See the README file for more on possible bugs you may encounter.

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 Changes file for specifics.

LICENSE Net::SCP::Expect is licensed under the same terms as Perl itself.

COPYRIGHT (C) 2003, 2004 Daniel J. Berger, All Rights Reserved

AUTHOR

Daniel Berger

djberg96 at yahoo dot com

imperator on IRC