Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
PHP: ssh2_sftp - Manual
[go: Go Back, main page]

PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

ssh2_shell" width="11" height="7"/> <ssh2_sftp_unlink
Last updated: Thu, 31 May 2007

view this page in

ssh2_sftp

(PECL ssh2:0.10-0.9)

ssh2_sftp — SFTP サブシステムを初期化する

説明

resource ssh2_sftp ( resource $session )

すでに接続された SSH2 サーバから SFTP サブシステムを要求します。

このメソッドは全ての他の ssh2_sftp_*() や ssh2.sftp:// fopen ラッパーで使用する SSH2 SFTP リソースを返します。

例 2312. SFTP 経由でファイルをオープンする

<?php
$connection
= ssh2_connect('shell.example.com', 22);
ssh2_auth_password($connection, 'username', 'password');

$sftp = ssh2_sftp($connection);

$stream = fopen("ssh2.sftp://$sftp/path/to/file", 'r');
?>

ssh2_scp_send(), ssh2_scp_recv() も参照ください。



add a note add a note User Contributed Notes
ssh2_sftp
David Barnes
16-Nov-2006 08:08
Here is an example of how to send a file with SFTP:

<?php

class SFTPConnection
{
   
private $connection;
   
private $sftp;

   
public function __construct($host, $port=22)
    {
       
$this->connection = @ssh2_connect($host, $port);
        if (!
$this->connection)
           
throw new Exception("Could not connect to $host on port $port.");
    }

   
public function login($username, $password)
    {
        if (! @
ssh2_auth_password($this->connection, $username, $password))
           
throw new Exception("Could not authenticate with username $username " .
                               
"and password $password.");

       
$this->sftp = @ssh2_sftp($this->connection);
        if (!
$this->sftp)
           
throw new Exception("Could not initialize SFTP subsystem.");
    }

   
public function uploadFile($local_file, $remote_file)
    {
       
$sftp = $this->sftp;
       
$stream = @fopen("ssh2.sftp://$sftp$remote_file", 'w');

        if (!
$stream)
           
throw new Exception("Could not open file: $remote_file");

       
$data_to_send = @file_get_contents($local_file);
        if (
$data_to_send === false)
           
throw new Exception("Could not open local file: $local_file.");

        if (@
fwrite($stream, $data_to_send) === false)
           
throw new Exception("Could not send data from file: $local_file.");

        @
fclose($stream);
    }
}

try
{
   
$sftp = new SFTPConnection("localhost", 22);
   
$sftp->login("username", "password");
   
$sftp->uploadFile("/tmp/to_be_sent", "/tmp/to_be_received");
}
catch (Exception $e)
{
    echo
$e->getMessage() . "\n";
}

?>

ssh2_shell" width="11" height="7"/> <ssh2_sftp_unlink
Last updated: Thu, 31 May 2007
 
 
show source | credits | sitemap | contact | advertising | mirror sites