开发者

FTP transfer all files in a remote directory, and tweak permissions, using PHP

开发者 https://www.devze.com 2022-12-29 15:25 出处:网络
How can I download folder from some ftp server into my server home directory and give to that d开发者_C百科irectory rights (like all files in this directory have all or no rights)?

How can I download folder from some ftp server into my server home directory and give to that d开发者_C百科irectory rights (like all files in this directory have all or no rights)?

Not using special libraries if it is possible.


<?php
file_put_contents('./file.txt', file_get_contents('ftp://server/file.txt'));
?>

The FTP server must support passive mode (ref) and your web server must have allow_url_fopen set in the php.ini (ref).

To give rights use chmod('./file.txt', 0777) or whatever rights you need.


I think you may want PHP's functions for FTP such as ftp_nlist and ftp_nb_get:

http://www.w3schools.com/PHP/php_ref_ftp.asp

I also found this resource which looks like a good tutorial as well as usable code:

http://www.raditha.com/php/ftp/pasv.php

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号