185 |
199 |
186 // chmod the file or directory |
200 // chmod the file or directory |
187 return $this->ftp->chmod($file, $mode); |
201 return $this->ftp->chmod($file, $mode); |
188 } |
202 } |
189 |
203 |
190 function owner($file) { |
204 /** |
|
205 * @param string $file |
|
206 * @return string |
|
207 */ |
|
208 public function owner($file) { |
191 $dir = $this->dirlist($file); |
209 $dir = $this->dirlist($file); |
192 return $dir[$file]['owner']; |
210 return $dir[$file]['owner']; |
193 } |
211 } |
194 |
212 /** |
195 function getchmod($file) { |
213 * @param string $file |
|
214 * @return string |
|
215 */ |
|
216 public function getchmod($file) { |
196 $dir = $this->dirlist($file); |
217 $dir = $this->dirlist($file); |
197 return $dir[$file]['permsn']; |
218 return $dir[$file]['permsn']; |
198 } |
219 } |
199 |
220 /** |
200 function group($file) { |
221 * @param string $file |
|
222 * @return string |
|
223 */ |
|
224 public function group($file) { |
201 $dir = $this->dirlist($file); |
225 $dir = $this->dirlist($file); |
202 return $dir[$file]['group']; |
226 return $dir[$file]['group']; |
203 } |
227 } |
204 |
228 /** |
205 function copy($source, $destination, $overwrite = false, $mode = false) { |
229 * @param string $source |
|
230 * @param string $destination |
|
231 * @param bool $overwrite |
|
232 * @param int|bool $mode |
|
233 * @return bool |
|
234 */ |
|
235 public function copy($source, $destination, $overwrite = false, $mode = false) { |
206 if ( ! $overwrite && $this->exists($destination) ) |
236 if ( ! $overwrite && $this->exists($destination) ) |
207 return false; |
237 return false; |
208 |
238 |
209 $content = $this->get_contents($source); |
239 $content = $this->get_contents($source); |
210 if ( false === $content ) |
240 if ( false === $content ) |
211 return false; |
241 return false; |
212 |
242 |
213 return $this->put_contents($destination, $content, $mode); |
243 return $this->put_contents($destination, $content, $mode); |
214 } |
244 } |
215 |
245 /** |
216 function move($source, $destination, $overwrite = false ) { |
246 * @param string $source |
|
247 * @param string $destination |
|
248 * @param bool $overwrite |
|
249 * @return bool |
|
250 */ |
|
251 public function move($source, $destination, $overwrite = false ) { |
217 return $this->ftp->rename($source, $destination); |
252 return $this->ftp->rename($source, $destination); |
218 } |
253 } |
219 |
254 /** |
220 function delete($file, $recursive = false, $type = false) { |
255 * @param string $file |
|
256 * @param bool $recursive |
|
257 * @param string $type |
|
258 * @return bool |
|
259 */ |
|
260 public function delete($file, $recursive = false, $type = false) { |
221 if ( empty($file) ) |
261 if ( empty($file) ) |
222 return false; |
262 return false; |
223 if ( 'f' == $type || $this->is_file($file) ) |
263 if ( 'f' == $type || $this->is_file($file) ) |
224 return $this->ftp->delete($file); |
264 return $this->ftp->delete($file); |
225 if ( !$recursive ) |
265 if ( !$recursive ) |
226 return $this->ftp->rmdir($file); |
266 return $this->ftp->rmdir($file); |
227 |
267 |
228 return $this->ftp->mdel($file); |
268 return $this->ftp->mdel($file); |
229 } |
269 } |
230 |
270 |
231 function exists( $file ) { |
271 /** |
|
272 * @param string $file |
|
273 * @return bool |
|
274 */ |
|
275 public function exists( $file ) { |
232 $list = $this->ftp->nlist( $file ); |
276 $list = $this->ftp->nlist( $file ); |
|
277 |
|
278 if ( empty( $list ) && $this->is_dir( $file ) ) { |
|
279 return true; // File is an empty directory. |
|
280 } |
|
281 |
233 return !empty( $list ); //empty list = no file, so invert. |
282 return !empty( $list ); //empty list = no file, so invert. |
234 // return $this->ftp->is_exists($file); has issues with ABOR+426 responses on the ncFTPd server |
283 // Return $this->ftp->is_exists($file); has issues with ABOR+426 responses on the ncFTPd server. |
235 } |
284 } |
236 |
285 |
237 function is_file($file) { |
286 /** |
|
287 * @param string $file |
|
288 * @return bool |
|
289 */ |
|
290 public function is_file($file) { |
238 if ( $this->is_dir($file) ) |
291 if ( $this->is_dir($file) ) |
239 return false; |
292 return false; |
240 if ( $this->exists($file) ) |
293 if ( $this->exists($file) ) |
241 return true; |
294 return true; |
242 return false; |
295 return false; |
243 } |
296 } |
244 |
297 |
245 function is_dir($path) { |
298 /** |
|
299 * @param string $path |
|
300 * @return bool |
|
301 */ |
|
302 public function is_dir($path) { |
246 $cwd = $this->cwd(); |
303 $cwd = $this->cwd(); |
247 if ( $this->chdir($path) ) { |
304 if ( $this->chdir($path) ) { |
248 $this->chdir($cwd); |
305 $this->chdir($cwd); |
249 return true; |
306 return true; |
250 } |
307 } |
251 return false; |
308 return false; |
252 } |
309 } |
253 |
310 |
254 function is_readable($file) { |
311 /** |
|
312 * @param string $file |
|
313 * @return bool |
|
314 */ |
|
315 public function is_readable($file) { |
255 return true; |
316 return true; |
256 } |
317 } |
257 |
318 |
258 function is_writable($file) { |
319 /** |
|
320 * @param string $file |
|
321 * @return bool |
|
322 */ |
|
323 public function is_writable($file) { |
259 return true; |
324 return true; |
260 } |
325 } |
261 |
326 |
262 function atime($file) { |
327 /** |
|
328 * @param string $file |
|
329 * @return bool |
|
330 */ |
|
331 public function atime($file) { |
263 return false; |
332 return false; |
264 } |
333 } |
265 |
334 |
266 function mtime($file) { |
335 /** |
|
336 * @param string $file |
|
337 * @return int |
|
338 */ |
|
339 public function mtime($file) { |
267 return $this->ftp->mdtm($file); |
340 return $this->ftp->mdtm($file); |
268 } |
341 } |
269 |
342 |
270 function size($file) { |
343 /** |
|
344 * @param string $file |
|
345 * @return int |
|
346 */ |
|
347 public function size($file) { |
271 return $this->ftp->filesize($file); |
348 return $this->ftp->filesize($file); |
272 } |
349 } |
273 |
350 /** |
274 function touch($file, $time = 0, $atime = 0 ) { |
351 * @param string $file |
|
352 * @param int $time |
|
353 * @param int $atime |
|
354 * @return bool |
|
355 */ |
|
356 public function touch($file, $time = 0, $atime = 0 ) { |
275 return false; |
357 return false; |
276 } |
358 } |
277 |
359 |
278 function mkdir($path, $chmod = false, $chown = false, $chgrp = false ) { |
360 /** |
|
361 * @param string $path |
|
362 * @param mixed $chmod |
|
363 * @param mixed $chown |
|
364 * @param mixed $chgrp |
|
365 * @return bool |
|
366 */ |
|
367 public function mkdir($path, $chmod = false, $chown = false, $chgrp = false ) { |
279 $path = untrailingslashit($path); |
368 $path = untrailingslashit($path); |
280 if ( empty($path) ) |
369 if ( empty($path) ) |
281 return false; |
370 return false; |
282 |
371 |
283 if ( ! $this->ftp->mkdir($path) ) |
372 if ( ! $this->ftp->mkdir($path) ) |
284 return false; |
373 return false; |
285 if ( ! $chmod ) |
374 if ( ! $chmod ) |
286 $chmod = FS_CHMOD_DIR; |
375 $chmod = FS_CHMOD_DIR; |
287 $this->chmod($path, $chmod); |
376 $this->chmod($path, $chmod); |
288 if ( $chown ) |
|
289 $this->chown($path, $chown); |
|
290 if ( $chgrp ) |
|
291 $this->chgrp($path, $chgrp); |
|
292 return true; |
377 return true; |
293 } |
378 } |
294 |
379 |
295 function rmdir($path, $recursive = false ) { |
380 /** |
|
381 * @param sting $path |
|
382 * @param bool $recursive |
|
383 */ |
|
384 public function rmdir($path, $recursive = false ) { |
296 $this->delete($path, $recursive); |
385 $this->delete($path, $recursive); |
297 } |
386 } |
298 |
387 |
299 function dirlist($path = '.', $include_hidden = true, $recursive = false ) { |
388 /** |
|
389 * @param string $path |
|
390 * @param bool $include_hidden |
|
391 * @param bool $recursive |
|
392 * @return bool|array |
|
393 */ |
|
394 public function dirlist($path = '.', $include_hidden = true, $recursive = false ) { |
300 if ( $this->is_file($path) ) { |
395 if ( $this->is_file($path) ) { |
301 $limit_file = basename($path); |
396 $limit_file = basename($path); |
302 $path = dirname($path) . '/'; |
397 $path = dirname($path) . '/'; |
303 } else { |
398 } else { |
304 $limit_file = false; |
399 $limit_file = false; |