note 125860 added to function.ftp-put
| From: | jan at odvarko dot cz | Date: | Fri, 26 Feb 2021 09:42:02 +0000 |
| Subject: | note 125860 added to function.ftp-put | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-219296@lists.php.net to get a copy of this message | ||
Yet another recursive ftp_put.
* The parameters are similar to that of ftp_put, so if you need to copy a directory, just use
ftp_put_dir(...) instead of ftp_put(...).
* Another advantage is that the remote directory doesn't need to exist.
* Returns TRUE on success, FALSE on failure.
* Inspired by lucas at rufy dot com and webmaster at sweetphp dot com.
<?php
function ftp_put_dir($ftp, $remote_dirname, $local_dirname, $mode=FTP_BINARY) {
$success = true;
// If necessary, create the remote directory.
if (!ftp_nlist($ftp, $remote_dirname)) {
if (ftp_mkdir($ftp, $remote_dirname) === false) {
$success = false;
}
}
$dir = dir($local_dirname);
while ($f = $dir->read()) {
if ($f === '.' || $f === '..') {
continue;
}
$lf = $local_dirname . '/' . $f;
$rf = $remote_dirname . '/' . $f;
if (is_dir($lf)) {
if (!ftp_put_dir($ftp, $rf, $lf, $mode)) {
$success = false;
}
} else {
if (!ftp_put($ftp, $rf, $lf, $mode)) {
$success = false;
}
}
}
$dir->close();
return $success;
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 45.112.85.246 (proxied: 212.11.118.132)
----
Manual Page -- http://php.net/manual/en/function.ftp-put.php
Edit -- https://master.php.net/note/edit/125860
Del: integrated -- https://master.php.net/note/delete/125860/integrated
Del: useless -- https://master.php.net/note/delete/125860/useless
Del: bad code -- https://master.php.net/note/delete/125860/bad+code
Del: spam -- https://master.php.net/note/delete/125860/spam
Del: non-english -- https://master.php.net/note/delete/125860/non-english
Del: in docs -- https://master.php.net/note/delete/125860/in+docs
Del: other reasons-- https://master.php.net/note/delete/125860
Reject -- https://master.php.net/note/reject/125860
Search -- https://master.php.net/manage/user-notes.php