Apache common FTP(四)

2014-11-24 02:43:15 · 作者: · 浏览: 13
eakSuccess;

} else {

result = DownloadStatus.DownloadFromBreakFailed;

}

} else {

OutputStream out = new FileOutputStream(f);

InputStream in = ftpClient.retrieveFileStream(new String(remote

.getBytes("GBK"), "iso-8859-1"));

byte[] bytes = new byte[1024];

long step = lRemoteSize / 100;

step = step==0 1:step;//文件过小,step可能为0

long process = 0;

long localSize = 0L;

int c;

while ((c = in.read(bytes)) != -1) {

out.write(bytes, 0, c);

localSize += c;

long nowProcess = localSize / step;

if (nowProcess > process) {

process = nowProcess;

if (process % 10 == 0){

log.info("下载进度:" + process);

}

}

}

in.close();

out.close();

boolean upNewStatus = ftpClient.completePendingCommand();

if (upNewStatus) {

result = DownloadStatus.DownloadNewSuccess;

} else {

result = DownloadStatus.DownloadNewFailed;

}

}

return result;

}

public boolean changeDirectory(String path) throws IOException {

return ftpClient.changeWorkingDirectory(path);

}

public boolean createDirectory(String pathName) throws IOException {

return ftpClient.makeDirectory(pathName);

}

public boolean removeDirectory(String path) throws IOException {

return ftpClient.removeDirectory(path);

}

public boolean removeDirectory(String path, boolean isAll)

throws IOException {

if (!isAll) {

return removeDirectory(path);

}

FTPFile[] ftpFileArr = ftpClient.listFiles(path);

if (ftpFileArr == null || ftpFileArr.length == 0) {

return removeDirectory(path);

}

//

for (FTPFile ftpFile : ftpFileArr) {

String name = ftpFile.getName();

if (ftpFile.isDirectory()) {

log.info("* [sD]Delete subPath [" + path +