home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / phing / tasks / ext / ScpSendTask.php < prev    next >
Encoding:
PHP Script  |  2007-08-28  |  3.6 KB  |  193 lines

  1. <?php
  2. /**
  3.  * $Id: ScpSendTask.php 227 2007-08-28 02:17:00Z hans $
  4.  *
  5.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16.  *
  17.  * This software consists of voluntary contributions made by many individuals
  18.  * and is licensed under the LGPL. For more information please see
  19.  * <http://phing.info>.
  20.  */
  21.  
  22. require_once 'phing/Task.php';
  23.  
  24. /**
  25.  * SCPs a File to a remote server 
  26.  *
  27.  * @author Andrew Eddie <andrew.eddie@jamboworks.com> 
  28.  * @version $Id: ScpSendTask.php 227 2007-08-28 02:17:00Z hans $
  29.  * @package phing.tasks.ext
  30.  * @since 2.3.0
  31.  */
  32. class ScpSendTask extends Task
  33. {
  34.     private $localFile = "";
  35.  
  36.     private $remoteFile = "";
  37.  
  38.     private $username = "";
  39.  
  40.     private $password = "";
  41.  
  42.     private $host = "";
  43.  
  44.     private $port = 22;
  45.  
  46.     private $mode = null;
  47.  
  48.     private $_connection = null;
  49.  
  50.     /**
  51.      * Sets the remote host
  52.      */
  53.     function setHost($h)
  54.     {
  55.         $this->host = $h;
  56.     }
  57.  
  58.     /**
  59.      * Returns the remote host
  60.      */
  61.     function getHost()
  62.     {
  63.         return $this->host;
  64.     }
  65.  
  66.     /**
  67.      * Sets the remote host port
  68.      */
  69.     function setPort($p)
  70.     {
  71.         $this->port = $p;
  72.     }
  73.  
  74.     /**
  75.      * Returns the remote host port
  76.      */
  77.     function getPort()
  78.     {
  79.         return $this->port;
  80.     }
  81.  
  82.     /**
  83.      * Sets the mode value
  84.      */
  85.     function setMode($value)
  86.     {
  87.         $this->mode = $value;
  88.     }
  89.  
  90.     /**
  91.      * Returns the mode value
  92.      */
  93.     function getMode()
  94.     {
  95.         return $this->mode;
  96.     }
  97.  
  98.     /**
  99.      * Sets the username of the user to scp
  100.      */
  101.     function setUsername($username)
  102.     {
  103.         $this->username = $username;
  104.     }
  105.  
  106.     /**
  107.      * Returns the username
  108.      */
  109.     function getUsername()
  110.     {
  111.         return $this->username;
  112.     }
  113.  
  114.     /**
  115.      * Sets the password of the user to scp
  116.      */
  117.     function setPassword($password)
  118.     {
  119.         $this->password = $password;
  120.     }
  121.  
  122.     /**
  123.      * Returns the password
  124.      */
  125.     function getPassword()
  126.     {
  127.         return $this->password;
  128.     }
  129.  
  130.     /**
  131.      * Sets the local path to scp from
  132.      */
  133.     function setLocalFile($lFile)
  134.     {
  135.         $this->localFile = $lFile;
  136.     }
  137.  
  138.     /**
  139.      * Returns the local path to scp from
  140.      */
  141.     function getLocalFile($lFile)
  142.     {
  143.         return $this->localFile;
  144.     }
  145.  
  146.     /**
  147.      * Sets the remote path to scp to
  148.      */
  149.     function setRemoteFile($rFile)
  150.     {
  151.         $this->remoteFile = $rFile;
  152.     }
  153.  
  154.     /**
  155.      * Returns the remote path to scp to
  156.      */
  157.     function getRemoteFile($rFile)
  158.     {
  159.         return $this->remoteFile;
  160.     }
  161.  
  162.     /**
  163.     * The init method: Do init steps.
  164.     */
  165.     public function init()
  166.     {
  167.         if (function_exists('ssh2_connect')) {
  168.             $this->_connection = ssh2_connect($this->host, $this->port);
  169.             ssh2_auth_password($this->_connection, $this->username, $this->password);
  170.         } else {
  171.             print ("ERROR: SSH Extension is not installed");
  172.         }
  173.     }
  174.  
  175.     /**
  176.      * The main entry point method.
  177.      */
  178.     public function main()
  179.     {
  180.         if (function_exists('ssh2_scp_send') && !is_null($this->_connection))
  181.         {
  182.             if (!is_null($this->mode)) {
  183.                 ssh2_scp_send($this->_connection, $this->localFile, $this->remoteFile, $this->mode);
  184.             } else {
  185.                 ssh2_scp_send($this->_connection, $this->localFile, $this->remoteFile);
  186.             }
  187.         } else {
  188.             print ("ERROR: No SSH Connection Available");
  189.         }
  190.     }
  191. }
  192. ?>
  193.