我正在使用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
}
经过一些调试后,死锁或延迟在此方法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;
}
方法调用一直被阻塞,直到它最终抛出socketTimeoutException,即使使用具有相同凭据和属性的FileZilla,我也可以在更快的时间内顺利地列出和读取文件。
我使用的凭据和属性正确,因为初始连接和fs.getFileStatus(somePath).isDirectory();
调用正常工作并返回正确的值。
是否有一个属性我可以添加,使事情更快,或它是一个错误,在apache hadoop FTPFileSystem版本3.2.0?
1条答案
按热度按时间mwkjh3gx1#
您可能需要将传输和/或连接模式更改为以下模式之一