简体   繁体   中英

Copy files from one DV server to another PHP

But what's the best and easiest way to copy a file or folder between a local and remote server using php? These are files located above the web folder, so I'll need to use paths instead of the URL.

I would do it using PHP's built-in FTP functions.

EDIT: Ahh, you want secure. This is what I would use then: SSH2-SFTP

Well i made this function hope it works for you copy files from ftp: $ftpConnection = the conection, example ftp_connect(1.0.0.1). $path = the ftp path. $destination = the local file.

function ftpRecursiveFileListing($ftpConnection, $path, $destination) {
    $contents = ftp_nlist($ftpConnection, $path);
    foreach ($contents as $currentFile) {
        if (strpos($currentFile, '.') === false) {
            $dir = basename($currentFile);
            echo "<br> <b> Directorio </b>" . $dir;
            mkdir($destination . "/" . $dir);
            ftpRecursiveFileListing($ftpConnection, $currentFile, $destination . "/" .   $dir);
        } else {
            $file = basename($currentFile);
            echo '<br> <b>archivo </b>' . $file;
            echo '<br> <b>path </b>' . $path;
            echo '<br> <b>completo </b>' . $path . "/" . $file;
            ftp_get($ftpConnection, $destination . '/' . $file, $path . '/' . $file, FTP_BINARY);
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM