CURL FTP连接仅在托管时被拒绝

问题描述

我使用PHP和Curl连接到FTP服务器, 奇怪的是,当我在本地设置中尝试我的代码时,它以隐式TLS和显式TLS两种方式工作,但是当我在任何服务器上运行相同的代码时,它不起作用并返回Connection refused。 / p>

PHP代码为:

<?php

function simple_list_test() {
    $curlopts = [];
    $debug = true;
    $return = null;
    
    $curlopts[CURLOPT_USERPWD] = "{$user}:{$password}";
    $curlopts[CURLOPT_SSL_VERIFYPEER] = false;
    $curlopts[CURLOPT_SSL_VERIFYHOST] = false;
    $curlopts[CURLOPT_FTP_SSL] = CURLFTPSSL_TRY;
    $curlopts[CURLOPT_FTPSSLAUTH] = CURLFTPAUTH_TLS;
    $curlopts[CURLOPT_RETURNTRANSFER] = true;
    $curlopts[CURLOPT_URL] = "ftp://ftp.avidafinance.com:21/"; // I tried with ftps:// protocol too it works on local but not when you run it on a hosting
    $curlopts[CURLOPT_FTPLISTONLY] = 1;
    $curlopts[CURLOPT_UPLOAD] = 0;
    $curlopts[CURLOPT_RETURNTRANSFER] = 1;

    $ch = curl_init();

    foreach($curlopts as $key => $value) {
        curl_setopt($ch,$key,$value);
    }

    if ($debug) {
        curl_setopt($ch,CURLOPT_VERBOSE,true);
        $verbose = fopen('php://temp','w+');
        curl_setopt($ch,CURLOPT_STDERR,$verbose);
    }

    $return = curl_exec($ch);

    if ($debug) {
        rewind($verbose);
        $verboseLog = stream_get_contents($verbose);
        echo "Verbose information:\n<pre>",htmlspecialchars($verboseLog),"</pre>\n";
    }

    if ($error = curl_error($ch)) {
        throw new Exception($error);
    }

    return $return;
}

我花了一整天时间,尝试了许多方法,包括设置CURLOPT_PORT,设置ftps://协议,增加超时时间,包括服务器.crt.pem带有curl的证书,但是他们都没有工作,所以我想知道是否有人可以帮我

这是在PHP 7.3和curl 7.68.0本地开发环境中的详细输出摘要:

*   Trying 13.53.118.182:21...
* TCP_NODELAY set
* Connected to ftp.avidafinance.com (13.53.118.182) port 21 (#0)
< 220 FileZilla Server 0.9.60 beta
> AUTH TLS
< 234 Using authentication type TLS
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* Server certificate:
*  subject: OU=Domain Control Validated; CN=ftp.avidafinance.com
*  start date: Mar 23 12:46:23 2020 GMT
*  expire date: Mar 23 12:46:23 2022 GMT
*  issuer: C=US; ST=Arizona; L=Scottsdale; O=GoDaddy.com,Inc.; OU=http://certs.godaddy.com/repository/; CN=Go Daddy Secure Certificate Authority - G2
*  SSL certificate verify ok.
> USER ****
< 331 Password required for *****
> PASS *****
< 230 Logged on
> PBSZ 0
< 200 PBSZ=0
> PROT P
< 200 Protection level set to P
> PWD
< 257 "/" is current directory.
* Entry path is '/'
* Request has same path as previous transfer
> EPSV
* Connect data stream passively
* ftp_perform ends with SECONDARY: 0
< 229 Entering Extended Passive Mode (|||57081|)
*   Trying 13.53.118.182:57081...
* TCP_NODELAY set
* Connecting to 13.53.118.182 (13.53.118.182) port 57081
* Connected to ftp.avidafinance.com (13.53.118.182) port 21 (#0)
> TYPE A
< 200 Type set to A
> NLST
< 150 Opening data channel for directory listing of "/"
* Maxdownload = -1
* Doing the SSL/TLS handshake on the data stream
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* SSL re-using session ID
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* Server certificate:
*  subject: OU=Domain Control Validated; CN=ftp.avidafinance.com
*  start date: Mar 23 12:46:23 2020 GMT
*  expire date: Mar 23 12:46:23 2022 GMT
*  issuer: C=US; ST=Arizona; L=Scottsdale; O=GoDaddy.com,Inc.; OU=http://certs.godaddy.com/repository/; CN=Go Daddy Secure Certificate Authority - G2
*  SSL certificate verify ok.
* Remembering we are in dir ""
< 226 Successfully transferred "/"
* Connection #0 to host ftp.avidafinance.com left intact

但是当我在主机上运行完全相同的代码(尝试了3个以上的不同服务器)时,它将像这样:

*   Trying 13.53.118.182...
* TCP_NODELAY set
* Connected to ftp.avidafinance.com (13.53.118.182) port 21 (#0)
< 220 FileZilla Server 0.9.60 beta
> AUTH TLS
< 234 Using authentication type TLS
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* Server certificate:
*  subject: OU=Domain Control Validated; CN=ftp.avidafinance.com
*  start date: Mar 23 12:46:23 2020 GMT
*  expire date: Mar 23 12:46:23 2022 GMT
*  issuer: C=US; ST=Arizona; L=Scottsdale; O=GoDaddy.com,Inc.; OU=http://certs.godaddy.com/repository/; CN=Go Daddy Secure Certificate Authority - G2
*  SSL certificate verify ok.
> USER *****
< 331 Password required for ******
> PASS *****
< 230 Logged on
> PBSZ 0
< 200 PBSZ=0
> PROT P
< 200 Protection level set to P
> PWD
< 257 "/" is current directory.
* Entry path is '/'
> EPSV
* Connect data stream passively
* ftp_perform ends with SECONDARY: 0
< 229 Entering Extended Passive Mode (|||57093|)
*   Trying 13.53.118.182...
* TCP_NODELAY set
* Connecting to 13.53.118.182 (13.53.118.182) port 57093
* connect to 13.53.118.182 port 21 failed: Connection refused
* Failed to connect to ftp.avidafinance.com port 21: Connection refused
* Failed EPSV attempt. Disabling EPSV
> PASV
< 227 Entering Passive Mode (13,53,118,182,222,194)
*   Trying 13.53.118.182...
* TCP_NODELAY set
* Connecting to 13.53.118.182 (13.53.118.182) port 57026
* connect to 13.53.118.182 port 21 failed: Connection refused
* Failed to connect to ftp.avidafinance.com port 21: Connection refused
* Closing connection 0

简而言之,我需要一个Explicit FTP Over TLS连接,我尝试了curlftp_ssl_connect fsockets,...。它们都不起作用,我将不胜感激,不一定一定要卷曲

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)