Hadoop FTPFileSystem 无法列出文件并抛出 SocketTimeOutException

Sel*_*wwa 5 java ftp hadoop

我正在使用 Apache Hadoop FTPFileSystem版本 3.2.0 来列出和读取来自 FTP 服务器的文件。

这是我的测试代码:

public static void main(String[] args) throws IOException {
    String host = "some-host";
    int port = 21;
    Configuration conf = new Configuration(false);
    conf.set("fs.ftp.host", host);
    conf.setInt("fs.ftp.host.port", port);
    conf.set("fs.ftp.user." + host, "username");
    conf.set("fs.ftp.password." + host, "password");
    conf.set("fs.ftp.data.connection.mode", "PASSIVE_LOCAL_DATA_CONNECTION_MODE");
    conf.set("fs.ftp.impl", "org.apache.hadoop.fs.ftp.FTPFileSystem");
    
    String fsURL = String.format("ftp://%s:%s", host, String.valueOf(port));
    conf.set("fs.default.name", fsURL);
    FileSystem fs =  FileSystem.newInstance(conf);
    Path somePath = new Path("actual/path");
    fs.getFileStatus(somePath).isDirectory(); // returns true
    fs.listStatus(somePath); // keeps spinning then throws SocketTimeOutException
}
Run Code Online (Sandbox Code Playgroud)

org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPFileEntryParser, String)经过一些调试后,该方法执行时发生死锁或延迟:engine.readServerList(socket.getInputStream(), getControlEncoding());如下:

private FTPListParseEngine initiateListParsing(
        FTPFileEntryParser parser, String pathname)
throws IOException
{
    Socket socket = _openDataConnection_(FTPCmd.LIST, getListArguments(pathname));

    FTPListParseEngine engine = new FTPListParseEngine(parser, __configuration);
    if (socket == null)
    {
        return engine;
    }

    try {
        engine.readServerList(socket.getInputStream(), getControlEncoding());
    }
    finally {
        Util.closeQuietly(socket);
    }

    completePendingCommand();
    return engine;
}
Run Code Online (Sandbox Code Playgroud)

该方法调用一直处于阻塞状态,直到最终抛出 socketTimeoutException,尽管使用具有相同凭据和属性的 FileZilla 我可以以更快的速度顺利列出和读取文件。

我正在使用的凭据和属性是正确的,因为初始连接和fs.getFileStatus(somePath).isDirectory();调用有效并返回正确的值。

是否有我可以添加的属性以使速度更快,或者这是 apache hadoop FTPFileSystem 版本 3.2.0 中的错误?

Kho*_*lam 2

您可能需要将传输和/或连接模式更改为以下其中一种


conf.set("fs.ftp.transfer.mode", "COMPRESSED_TRANSFER_MODE");
// OR
conf.set("fs.ftp.transfer.mode", "STREAM_TRANSFER_MODE");

// AND

conf.set("fs.ftp.data.connection.mode", "PASSIVE_LOCAL_DATA_CONNECTION_MODE");
// OR
conf.set("fs.ftp.data.connection.mode", "PASSIVE_REMOTE_DATA_CONNECTION_MODE");
Run Code Online (Sandbox Code Playgroud)