PHP download from remote server via sftp

前端 未结 3 1650
不思量自难忘°
不思量自难忘° 2021-02-04 17:05

This may have been asked before, I\'m new to PHP and I\'m trying to learn as much as I can, but this has really thrown me.

Basically what I want to know is, how would I

3条回答
  •  忘掉有多难
    2021-02-04 18:04

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

    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(!ssh2_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("ssh2.sftp://{$stream}{$remoteDir}")
    

提交回复
热议问题