note 69267 deleted from function.mkdir by felipe
| From: | felipe@php.net | Date: | Mon, 10 Dec 2007 18:05:37 +0000 |
| Subject: | note 69267 deleted from function.mkdir by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-133253@lists.php.net to get a copy of this message | ||
Note Submitter: Lars Pätzold
----
Just a small addition to Han Van den Hoof's ftp script which is really useful for scripts on
shared servers.
I added a chmod command. This is necessary if you want to access the directory later via script.
I also fixed the small bug with the 2 variables connection & conn_id ;)
And last not least ftp connection is closed even if ftp commands fail.
Sometimes ftp login will fail due to bad luck. Therefore one should add a loop for retrying.
<?php
// create directory through FTP connection
function FtpMkdir($path, $newDir) {
$server='ftp.yourserver.com'; // ftp server
$connection = ftp_connect($server); // connection
// login to ftp server
$user = "me";
$pass = "password";
$result = ftp_login($connection, $user, $pass);
// check if connection was made
if ((!$connection) || (!$result)) {
return false;
exit();
} else {
if (!ftp_chdir($connection, $path)) { // go to destination dir
$r = false;
} else if (!ftp_mkdir($connection,$newDir)) { // create directory
$r = false;
} else if (!ftp_site($connection, "CHMOD 0777 $newDir") { // change attributes
$r = false;
} else {
$r = $newDir;
}
}
ftp_close($connection); // close connection
return $r;
}
?>