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

pgvzfuti  于 2022-11-21  发布在  Hadoop
关注(0)|答案(1)|浏览(337)

我正在使用Apache Hadoop FTPFileSystem 3.2.0版列出和读取FTP服务器中的文件。
下面是我的测试代码:

  1. public static void main(String[] args) throws IOException {
  2. String host = "some-host";
  3. int port = 21;
  4. Configuration conf = new Configuration(false);
  5. conf.set("fs.ftp.host", host);
  6. conf.setInt("fs.ftp.host.port", port);
  7. conf.set("fs.ftp.user." + host, "username");
  8. conf.set("fs.ftp.password." + host, "password");
  9. conf.set("fs.ftp.data.connection.mode", "PASSIVE_LOCAL_DATA_CONNECTION_MODE");
  10. conf.set("fs.ftp.impl", "org.apache.hadoop.fs.ftp.FTPFileSystem");
  11. String fsURL = String.format("ftp://%s:%s", host, String.valueOf(port));
  12. conf.set("fs.default.name", fsURL);
  13. FileSystem fs = FileSystem.newInstance(conf);
  14. Path somePath = new Path("actual/path");
  15. fs.getFileStatus(somePath).isDirectory(); // returns true
  16. fs.listStatus(somePath); // keeps spinning then throws SocketTimeOutException
  17. }

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

  1. private FTPListParseEngine initiateListParsing(
  2. FTPFileEntryParser parser, String pathname)
  3. throws IOException
  4. {
  5. Socket socket = _openDataConnection_(FTPCmd.LIST, getListArguments(pathname));
  6. FTPListParseEngine engine = new FTPListParseEngine(parser, __configuration);
  7. if (socket == null)
  8. {
  9. return engine;
  10. }
  11. try {
  12. engine.readServerList(socket.getInputStream(), getControlEncoding());
  13. }
  14. finally {
  15. Util.closeQuietly(socket);
  16. }
  17. completePendingCommand();
  18. return engine;
  19. }

方法调用一直被阻塞,直到它最终抛出socketTimeoutException,即使使用具有相同凭据和属性的FileZilla,我也可以在更快的时间内顺利地列出和读取文件。
我使用的凭据和属性正确,因为初始连接和fs.getFileStatus(somePath).isDirectory();调用正常工作并返回正确的值。
是否有一个属性我可以添加,使事情更快,或它是一个错误,在apache hadoop FTPFileSystem版本3.2.0?

mwkjh3gx

mwkjh3gx1#

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

  1. conf.set("fs.ftp.transfer.mode", "COMPRESSED_TRANSFER_MODE");
  2. // OR
  3. conf.set("fs.ftp.transfer.mode", "STREAM_TRANSFER_MODE");
  4. // AND
  5. conf.set("fs.ftp.data.connection.mode", "PASSIVE_LOCAL_DATA_CONNECTION_MODE");
  6. // OR
  7. conf.set("fs.ftp.data.connection.mode", "PASSIVE_REMOTE_DATA_CONNECTION_MODE");

相关问题