note 80912 added to function.ftp-fget
| From: | justrafi at gmail dot com | Date: | Wed, 06 Feb 2008 16:44:00 +0000 |
| Subject: | note 80912 added to function.ftp-fget | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-135823@lists.php.net to get a copy of this message | ||
I was in need to synchronize two folders on two separate servers, one is a Windows server, and the
other is a Linux server. I created this short and sweet function to help me do this. PLEASE NOTICE:
This will not copy folders, and probably will fail if remote folder contains anything else than
files.
function sync_folders($host, $port, $username, $password, $remote_dir, $local_dir, $passive_mode =
true) {
$conn_id = ftp_connect($host, $port);
if (!$conn_id) return false; # fail to connect
if (!ftp_login($conn_id, $username, $password)) { ftp_close($conn_id); return false; } # fail to
login
ftp_pasv($conn_id, $passive_mode);
if (!ftp_chdir($conn_id, $remote_dir)) { ftp_close($conn_id); return false; } # fail to change dir
if (substr($local_dir, -1) != '/') $local_dir .= '/';
$list = ftp_nlist($conn_id, '.');
sort($list);
foreach ($list as $file) {
if (!file_exists($local_dir . $file)) {
$is_copied = ftp_get($conn_id, $local_dir . $file, $file, FTP_BINARY);
}
}
ftp_close($conn_id);
return true;
}
----
Server IP: 82.80.248.162
Probable Submitter: 80.179.201.179
----
Manual Page -- http://www.php.net/manual/en/function.ftp-fget.php
Edit -- https://master.php.net/note/edit/80912
Del: integrated -- https://master.php.net/note/delete/80912/integrated
Del: useless -- https://master.php.net/note/delete/80912/useless
Del: bad code -- https://master.php.net/note/delete/80912/bad+code
Del: spam -- https://master.php.net/note/delete/80912/spam
Del: non-english -- https://master.php.net/note/delete/80912/non-english
Del: in docs -- https://master.php.net/note/delete/80912/in+docs
Del: other reasons-- https://master.php.net/note/delete/80912
Reject -- https://master.php.net/note/reject/80912
Search -- https://master.php.net/manage/user-notes.php