doujiao7520 2010-10-28 17:20
浏览 241
已采纳

在PHP中获取ftp_get()的警告

I try to retrieve a text file using ftp_get() and when I execute the script I get warning:

ftp_get() [function.ftp-get]: Can't open data connection

Can some one give some clue what is wrong. This was working on my previous hosting/server since I moved it it broke. Are there some specific PHP configurations. I checked the phpinfo and the FTP support is enabled. The connection got resource id and the username, password and ftp host work through CuteFTP.

function _getFtpFile( $fileName = '' ) {
    if($fileName == '') {
        return false;
    }

    $model = $this->getModel();
    $params =& $model->getParams();

    $vebraHost = $params->get('vebra_host');
    $vebraUser = $params->get('vebra_username');
    $vebraPass = $params->get('vebra_password');
    $localFile = JPATH_BASE.'/tmp/tmp.csv';

    // Delete the file in case it exists
    @unlink($localFile);

    // set up basic connection
    $connId = ftp_connect($vebraHost);

    // login with username and password
    $loginResult = ftp_login($connId, $vebraUser, $vebraPass);

    // turn on passive mode transfers
    ftp_pasv($connId, true);

    // try to download $server_file and save to $localFile
    if (!ftp_get($connId, $localFile, $fileName, FTP_BINARY)) {
        $file = false;
    } else {
        $file = $localFile;
    }

    // close the connection
    ftp_close($connId);

    return $file;
}
  • 写回答

2条回答 默认 最新

  • duanan2732 2010-10-28 18:11
    关注

    To be honest, this sounds like an FTP problem, not a PHP problem, as a "Can't open data connection" is an FTP error 425, which is a FTP protocol level error. There are plenty of problems that an FTP server can cause, especially one that is misconfigured.

    If I were to guess, I would say the problem lies within the configuration of the FTP server, possibly in the active/passive settings, but probably somewhere in their firewall settings. It could also lie in yours, but that seems unlikely, as you can still connect via CuteFTP.

    Is the FTP server a remote server, or is the same one that script is hosted on? It's very possible there could be port conflicts if they are the same. I would get in contact with your hosting's support, see if they recognize it as an issue.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符