Net::scp::expect Module Detailed

Source: Internet
Author: User
Tags file copy

Example:

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:&NBSP;SCP ()  with explicit IPv6 host in to or from  Address must use square brackets       see the &NBSP;SCP ()  method for more information on valid syntax

The above shows some ways to interact with the remote side.

Copy the files from the remote server to this computer.

Example 1; The test code is as follows:

#!/usr/bin/perluse v5.10;use warnings;use net::scp::expect; #定义远程服务器的ip login user and password; my $server = ' 192.168.0.128 '; my $user = ' Root '; my $pass = ' root12300. ';                #创建一个连接远程服务器的对象, my $SCP =net::scp::expect->new (host + $server, user = $user, Password=> $pass); #第一次登陆时, used for interactive $scp->auto_yes (1); $SCP->scp (":/test/src/app-cpanminus-1.7039.tar.gz ","/test/") or Die $scp->error_handler;say" file copy complete. OK ";
[Email protected] net]# lstest.pl[[email protected] net]# [[email protected] net]# ls/test/-ltotal 0[[email protected] net]#./test.pl file copy complete: Ok[[email protected] net]# ls/test/-ltotal 312-rw-r--r--1 root root 316814 15:55 app-cpanminus-1.7039.tar.gz[[em AIL protected] net]#

Copy the native files to the remote machine

Example 2: The test code is as follows (just change the file location in the SCP method to the line):

#!/usr/bin/perluse v5.10;use warnings;use net::scp::expect; #定义远程服务器的ip login user and password; my $server = ' 192.168.0.128 '; my $user = ' Root '; my $pass = ' root12300. '; #创建一个连接远程服务器的对象, my $scp =net::scp::expect->new (host=> $server,user=> $user,password=> $pass); #第一次登陆时, Used for interactive $scp->auto_yes (1), $SCP->scp ("/test/app-cpanminus-1.7039.tar.gz", ":/test/") or Die $SCP->error_ Handler;say "File copy complete. OK ";



SCP ()

     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, [email protected]:d estination); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SCP (source,  [email protected][ipv6-host]:d estination);   # same as previous, with &NBSP;IPV6&NBSP;HOST&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SCP (source, host:destination); #  USER&NBSP;ALREADY&NBSP;DEFINED&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SCP (Source, [ipv6-host]: destination);  # same as&NBSP;PREVIOUS,&NBSP;WITH&NBSP;IPV6&NBSP;HOST&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SCP (source, : Destination); # user and host already defined      &NBSP;&NBSP;SCP (source, destination); # same as previous     &NBSP;&NBSP;&NBSP;SCP (source);  # same as previous; destination will use  base name of source       remote to local &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SCP ([email protected]:source, destination);   &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SCP ([email protected][ipv6-host]:source, destination); #  SAME&NBSP;AS&NBSP;PREVIOUS,&NBSP;WITH&NBSP;IPV6&NBSP;HOST&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SCP (Host: source, destination); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SCP ([ipv6-host]:source, destination);  # same as previous,&NBSP;WITH&NBSP;IPV6&NBSP;HOST&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SCP (: source, destination); 

























Net::scp::expect Module Detailed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.