Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 连接到FTP服务器时出现错误“;ftp_login()要求参数1为资源,布尔值为“给定”;_Php - Fatal编程技术网

Php 连接到FTP服务器时出现错误“;ftp_login()要求参数1为资源,布尔值为“给定”;

Php 连接到FTP服务器时出现错误“;ftp_login()要求参数1为资源,布尔值为“给定”;,php,Php,当我尝试使用连接到FTP服务器时 ftp_ssl_connect() ,它给了我这个错误 ftp_login()要求参数1是资源,布尔值在 /第9行的home/web/public_html/FTP.php 这是我的源代码 <?php // set up basic ssl connection $conn_id = ftp_ssl_connect($host,'990','20'); // login with username and password $ftp_user_

当我尝试使用连接到FTP服务器时

ftp_ssl_connect()

,它给了我这个错误

ftp_login()要求参数1是资源,布尔值在 /第9行的home/web/public_html/FTP.php

这是我的源代码

    <?php

// set up basic ssl connection
$conn_id = ftp_ssl_connect($host,'990','20');

// login with username and password
$ftp_user_name='user';
$ftp_user_pass='pass';
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

if (!$login_result) {
    // PHP will already have raised an E_WARNING level message in this case
    die("can't login");
}

echo ftp_pwd($conn_id); // /

// close the ssl connection
ftp_close($conn_id);
?>

我得到了解决方案,实际上我的FTP连接是隐式的TLS FTP,因此必须使用CURL而不是FTP\u connect和FTP\u ssl\u connect。
我是这样做的

$fp = fopen('/', 'r');
$ftp_server = 'ftps://'.$server.'/'.$filename;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $ftp_server);
curl_setopt($ch, CURLOPT_USERPWD,$user.':'.$pass);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_FTP_SSL, CURLFTPSSL_TRY);
curl_setopt($ch, CURLOPT_FTPSSLAUTH, CURLFTPAUTH_TLS);
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_INFILE, $fp);

$output = curl_exec($ch);
$error_no = curl_errno($ch);
//var_dump(curl_error($ch));
curl_close($ch);

ftp_ssl_connec
返回
false
当无法通过ssl连接时,使用
ftp_connect
;实际上,我的FTP连接将通过TLS上的FTP工作,所以我使用了它。您的服务器上的端口990打开了吗??