![](/img/trans.png)
[英]Getting a list of directories and files from root directory from remote site via FTP using CURL and PHP
[英]cURL PHP FTP on hosting via limited list opened ports
我的主机可以通过有限的列表打开端口访问外部服务器。 我通过正确的端口连接到外部服务器,但没有获取文件列表等,因为扩展被动模式的端口已关闭:
* Trying 62.183.ХХ.ХХ:5666...
* TCP_NODELAY set
* Connected to 62.183.ХХ.ХХ (62.183.ХХ.ХХ) port 5666 (#0)
< 220 Microsoft FTP Service
> USER ****
< 331 Password required
> PASS ****
< 230 User logged in.
> PWD
< 257 "/" is current directory.
* Entry path is '/'
> EPSV
* Connect data stream passively
* ftp_perform ends with SECONDARY: 0
< 229 Entering Extended Passive Mode (|||50276|)
* Trying 62.183.ХХ.ХХ:50276...
* TCP_NODELAY set
* Connecting to 62.183.ХХ.ХХ (62.183.ХХ.ХХ) port 50276
* Operation timed out after 5001 milliseconds with 0 bytes received
* Closing connection 0
能做什么? 附言
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, FTPIP);
curl_setopt($ch, CURLOPT_PORT, FTPPORT);
curl_setopt($ch, CURLOPT_USERPWD, FTPUSER.":".FTPPASS);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_DIRLISTONLY, '1L');
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_STDERR, $verbose = fopen('php://temp', 'rw+'));
$files_list = curl_exec($ch);
$urlEndpoint = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
echo "Verbose information:\n<pre>", !rewind($verbose), htmlspecialchars(stream_get_contents($verbose)), "</pre>\n";
curl_close($ch);
这是我解决它的方法:首先获得一个便宜的vps(像this或this ,每月2美元,1.5TB带宽,不错,),然后在vps上安装nginx+libnginx-mod-http-lua,并制作一个脚本在 nginx 的默认 docroot 上安装目标 ftp 服务器。 像 /mounter.sh 包含
curlftpfs FTPIP /var/www/html/FTPIP -o ftp_method=singlecwd -o no_verify_hostname -o no_verify_peer -o utf8 -o allow_other -o big_writes -o user='FTPUSER:FTPPASS'
然后加
@reboot /bin/sh /mounter.sh
到你的根目录的crontab -e
所以它会在重新启动时自动重新安装,然后运行脚本,检查它是否安装正常.. 然后在 /etc/nginx/sites-enabled/default 添加
location /FTPIP_file_list {
content_by_lua_block {
os.execute("/bin/sh -c 'cd /var/www/html/FTPIP; find'");
}
}
最后将您的 php 脚本更改为
$ch = curl_init();
curl_setopt_array($ch,array(
CURLOPT_URL => "http://vps_ip/FTPIP_file_list",
CURLOPT_RETURNTRANSFER=>1
));
$files_list = curl_exec($ch);
...天哪,这比预期的要难。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.