成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

phpfreadbuffer問題

Here is a small code on how to read the folder and download all its files:

云州網站制作公司哪家好,找創(chuàng)新互聯(lián)!從網頁設計、網站建設、微信開發(fā)、APP開發(fā)、響應式網站設計等網站項目制作,到程序開發(fā),運營維護。創(chuàng)新互聯(lián)自2013年起到現在10年的時間,我們擁有了豐富的建站經驗和運維經驗,來保證我們的工作的順利進行。專注于網站建設就選創(chuàng)新互聯(lián)。

<?php
$host = 'localhost';$port = 22;$username = 'username';$password = 'password';$remoteDir = '/must/be/the/complete/folder/path';$localDir = '/can/be/the/relative/or/absolute/local/path';if (!function_exists("ssh3_connect"))
    die('Function ssh3_connect not found, you cannot use ssh3 here');if (!$connection = ssh3_connect($host, $port))
    die('Unable to connect');if (!ssh3_auth_password($connection, $username, $password))
    die('Unable to authenticate.');if (!$stream = ssh3_sftp($connection))
    die('Unable to create a stream.');if (!$dir = opendir("ssh3.sftp://{$stream}{$remoteDir}"))
    die('Could not open the directory');$files = array();while (false !== ($file = readdir($dir))){
    if ($file == "." || $file == "..")
        continue;
    $files[] = $file;}foreach ($files as $file){
    echo "Copying file: $file\n";
    if (!$remote = @fopen("ssh3.sftp://{$stream}/{$remoteDir}{$file}", 'r'))
    {
        echo "Unable to open remote file: $file\n";
        continue;
    }

    if (!$local = @fopen($localDir . $file, 'w'))
    {
        echo "Unable to create local file: $file\n";
        continue;
    }

    $read = 0;
    $filesize = filesize("ssh3.sftp://{$stream}/{$remoteDir}{$file}");
    while ($read < $filesize && ($buffer = fread($remote, $filesize - $read)))
    {
        $read += strlen($buffer);
        if (fwrite($local, $buffer) === FALSE)
        {
            echo "Unable to write to local file: $file\n";
            break;
        }
    }
    fclose($local);
    fclose($remote);}

You can also resume this code to (it will not copy directories):

while (false !== ($file = readdir($dirHandle))){
    if ($file == "." || $file == "..")
        continue;

    echo "Copying file: $file\n";
    if(!ssh3_scp_recv($connection, $remoteDir . $file, $localDir . $file))
        echo "Could not download: ", $remoteDir, $file, "\n";}

If you do not use the full path on the remote folder it will not work:

opendir("ssh3.sftp://{$stream}{$remoteDir}")

網頁名稱:phpfreadbuffer問題
文章路徑:http://jinyejixie.com/article0/jjheio.html

成都網站建設公司_創(chuàng)新互聯(lián),為您提供品牌網站制作外貿網站建設、微信公眾號、營銷型網站建設網站建設、定制網站

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

綿陽服務器托管
汽车| 富平县| 新化县| 特克斯县| 东源县| 昂仁县| 大厂| 金沙县| 云龙县| 宁强县| 威宁| 丽江市| 漳浦县| 福海县| 五指山市| 五台县| 喜德县| 天祝| 蕉岭县| 林西县| 仙游县| 冕宁县| 霍林郭勒市| 江阴市| 大姚县| 报价| 宜城市| 班戈县| 井陉县| 应用必备| 五常市| 天镇县| 廊坊市| 西和县| 宜川县| 双桥区| 临武县| 贵溪市| 黑山县| 运城市| 德令哈市|