dongye9071 2017-02-23 09:57 采纳率: 0%
浏览 232
已采纳

连接到FTP服务器给出错误“ftp_login()期望参数1是资源,布尔给定”

When i try to connect to FTP server using

ftp_ssl_connect()

, it is giving me this error

ftp_login() expects parameter 1 to be resource, boolean given in /home/web/public_html/FTP.php on line 9

Here is my source code

    <?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);
?>

I saw many question like this, but not given me any appropriate answers, please help.

  • 写回答

1条回答 默认 最新

  • doushi3322 2017-02-23 10:52
    关注

    I got the solution for this, actually my FTP connection is implicit FTP over TLS, so have to use CURL instead of ftp_connect and ftp_ssl_connect. I did it like below

    $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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?