【问题标题】:opendir() of an ftp url failsftp url 的 opendir() 失败
【发布时间】:2012-04-19 11:51:22
【问题描述】:

我正在尝试从远程服务器打开一个文件夹。我写道:

if ($folderHandle = opendir($folder))

在哪里$folder = "ftp://xxx:xxx@xxx.net:21"

我收到奇怪的错误Warning: opendir(ftp://...:21): failed to open dir: operation failed in ... on line 38

关于我应该从这里去哪里的任何想法?是 FTP 凭据有问题吗?

【问题讨论】:

    标签: php ftp


    【解决方案1】:

    您可以使用 PHP 的 FTP Capabilities 远程连接到服务器并获取目录列表:

    // set up basic connection
    $conn_id = ftp_connect('otherserver.example.com'); 
    
    // login with username and password
    $login_result = ftp_login($conn_id, 'username', 'password'); 
    
    // check connection
    if ((!$conn_id) || (!$login_result)) { 
        echo "FTP connection has failed!";
        exit; 
    }
    
    // upload the file
    $upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY); 
    
    // check upload status
    if (!$upload) { 
        echo "FTP upload has failed!";
    } else {
        echo "Uploaded $source_file to $ftp_server as $destination_file";
    }
    
    // Retrieve directory listing
    $files = ftp_nlist($conn_id, '/remote_dir');
    
    // close the FTP stream 
    ftp_close($conn_id);
    

    【讨论】:

    • ftp_connect 连接正常(在系统防火墙发出警告后),但我不想重写我的整个脚本:(
    • @Manu - 如果他们为您提供替代解决方案(如果存在?!),请等待其他用户。我尽力为您提供尽可能快的帮助...很抱歉,这不是您要找的:-/
    • 你的回答很好,如果我不能让opendir按预期工作,我会重写我的脚本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-07
    • 1970-01-01
    • 1970-01-01
    • 2012-06-26
    • 2013-08-25
    • 2012-01-09
    • 2017-03-03
    相关资源
    最近更新 更多