java apache commons net_java – apache commons net – completependingcommand返回false

我正在使用apache commons网络库从FTP服务器获取文件.

我不需要下载整个文件,只是为了读取标题来确定文件大小.我用来做这个的库是metadata extractor

问题是,当我调用client.completePendingCommand()时,它总是返回false – 但是日期变量是正确打印的.我问过元数据提取器的开发人员,他不知道为什么返回false.有人有解释吗?我不确定是否可以忽略这个错误?

FTPClient client = new FTPHTTPClient(proxy settings);

InputStream stream = null;

try {

client.connect(FTPProperties.getInstance().getProperty("ftp.server"));

client.login(FTPProperties.getInstance().getProperty("ftp.username"), FTPProperties.getInstance().getProperty("ftp.password"));

client.enterLocalPassiveMode();

for (String path : paths) { //paths are the jpeg files to download

try {

stream = client.retrieveFileStream(p);

Metadata metadata = ImageMetadataReader.readMetadata(stream);

Directory directory = metadata.getDirectory(ExifSubIFDDirectory.class);

Date date = directory.getDate(ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL);

System.out.println("DATE " + date);

} catch (IOException ex) {

Logger.getLogger(UploadImage.class.getName()).log(Level.SEVERE, null, ex);

} finally {

if(stream != null) {

stream.close();

}

if (in != null) {

in.close();

}

if (!client.completePendingCommand()) {

Logger.getLogger("Error");

}

}

}

} catch (Exception ex) {

Logger.getLogger(UploadImage.class.getName()).log(Level.SEVERE, null, ex);

} finally {

if (client != null && client.isConnected()) {

client.disconnect();

}

}

最佳答案 我不认为你做错了什么,我认为元数据提取器没有任何问题.您可能最好检查您正在检索的流可以正确处理,而不是使用completePendingCommand()作为成功的指示.元数据提取器可能已经通过在出现问题时抛出异常来为您执行此操作.

我有类似的问题,发现我的FTPClient对象的回复代码为150,表示根据FTP服务器,交易尚未完成.答复代码150是肯定的初步答复,但未被分类为肯定完成答复(http://tools.ietf.org/html/rfc959第37页).我的观点是响应仍然是积极的,虽然我认为我已经完成了交易,但FTP服务器仍然认为我需要做一些事情.这可能是org.apache.commons.net.ftp.FTPClient或与其交互的FTP服务器的问题.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值