note 90910 modified in function.ftp-get by danbrown

From: Date: Fri, 15 May 2009 19:43:30 +0000
Subject: note 90910 modified in function.ftp-get by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-154648@lists.php.net to get a copy of this message
ftp_sync is a way to walk the directory structure on the server and copy every directory and file to the same location locally. <?php $ftp_server = "ftp.example.com"; $conn_id = ftp_connect ($ftp_server) or die("Couldn't connect to $ftp_server"); $login_result = ftp_login($conn_id, "user", "pass"); if ((!$conn_id) || (!$login_result)) die("FTP Connection Failed"); ftp_sync ("DirectoryToCopy"); // Use "." if you are in the current directory ftp_close($conn_id); // ftp_sync - Copy directory and file structure function ftp_sync ($dir) { global $conn_id; if ($dir != ".") { if (ftp_chdir($conn_id, $dir) == false) { echo ("Change Dir Failed: $dir<BR>\r\n"); return; } if (!(is_dir($dir))) mkdir($dir); chdir ($dir); } $contents = ftp_nlist($conn_id, "."); foreach ($contents as $file) { if ($file == '.' || $file == '..') continue; if (@ftp_chdir($conn_id, $file)) { ftp_chdir ($conn_id, ".."); ftp_sync ($file); } else ftp_get($conn_id, $file, $file, FTP_BINARY); } ftp_chdir ($conn_id, ".."); chdir (".."); } ?> --was-- ftp_sync is a way to walk the directory structure on the server and copy every directory and file to the same location locally. $ftp_server = "ftp.example.com"; $conn_id = ftp_connect ($ftp_server) or die("Couldn't connect to $ftp_server"); $login_result = ftp_login($conn_id, "user", "pass"); if ((!$conn_id) || (!$login_result)) die("FTP Connection Failed"); ftp_sync ("DirectoryToCopy"); // Use "." if you are in the current directory ftp_close($conn_id); // ftp_sync - Copy directory and file structure function ftp_sync ($dir) { global $conn_id; if ($dir != ".") { if (ftp_chdir($conn_id, $dir) == false) { echo ("Change Dir Failed: $dir<BR>\r\n"); return; } if (!(is_dir($dir))) mkdir($dir); chdir ($dir); } $contents = ftp_nlist($conn_id, "."); foreach ($contents as $file) { if ($file == '.' || $file == '..') continue; if (@ftp_chdir($conn_id, $file)) { ftp_chdir ($conn_id, ".."); ftp_sync ($file); } else ftp_get($conn_id, $file, $file, FTP_BINARY); } ftp_chdir ($conn_id, ".."); chdir (".."); } http://php.net/manual/en/function.ftp-get.php

« previous php.notes (#154648) next »