如果出现问题,我需要在FTP客户端中恢复上传。在下面的示例中,ftp
是Apache FTPClient
。
public boolean upload(InputStream localFile, String remoteName, boolean createNew) {
if (StringUtils.isBlank(remoteName)) {
log.warn("Error while uploading file: localFile or remoteName is null");
return false;
}
synchronized (this) {
try {
if (createNew) {
return ftp.storeFile(remoteName, localFile);
} else {
return ftp.appendFile(remoteName, localFile); //todo is it right?
}
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
return false;
}
}
}
因此,如果ftp.storeFile
崩溃(例如,并非所有字节都已发送),如何使用相同的InputStream
继续上传?
答案 0 :(得分:1)
FTPClient.mlistFile
或SIZE
命令-请参见How to get info of an FTPFile); InputStream
不支持查找,因此您将不得不使用其他流实现-或重新打开InputStream
和skip
到该位置); FTPClient.appendFile
。