PHP中的FTP被动模式

问题描述 投票:1回答:1

需要在PHP文件中以被动模式设置FTP连接。

当我的连接详细信息如下时,不确定如何执行此操作:

protected $_credentials = array (
    'host'      => 'xxx.xxx.xxx.xxx',
    'user'      => 'xxxxx',
    'password'  => 'xxxxx',
    'timeout'   => '10'
    );

如何将被动模式添加到上面?

php ftp
1个回答
1
投票

假设你使用built-in PHP FTP functionsftp_*),使用ftp_pasv function,如:

$conn_id = ftp_connect($host) or die("Unable to connect to host");

ftp_login($conn_id, $user, $password) or die("Authorization failed");

// turn passive mode on
ftp_pasv($conn_id, true) or die("Unable switch to passive mode");

您的代码示例仅创建关联数组。它并没有真正做任何“FTP”。因此,如果您使用的是其他PHP FTP库,则必须告诉我们。

© www.soinside.com 2019 - 2024. All rights reserved.