Apache common FTP(八)

2014-11-24 02:43:15 · 作者: · 浏览: 7
while ((c = raf.read(bytes)) != -1) {

out.write(bytes, 0, c);

localreadbytes += c;

if (localreadbytes / step != process) {

process = localreadbytes / step;

if (process % 10 == 0){

log.info("上传进度:" + process);

}

}

}

out.flush();

raf.close();

out.close();

boolean result = ftpClient.completePendingCommand();

if (remoteSize > 0) {

status = result UploadStatus.UploadFromBreakSuccess

: UploadStatus.UploadFromBreakFailed;

} else {

status = result UploadStatus.UploadNewFileSuccess

: UploadStatus.UploadNewFileFailed;

}

return status;

}

public InputStream downFile(String sourceFileName) throws IOException {

return ftpClient.retrieveFileStream(sourceFileName);

}

public enum UploadStatus {

CreateDirectoryFail, // 远程服务器相应目录创建失败

CreateDirectorySuccess, // 远程服务器闯将目录成功

UploadNewFileSuccess, // 上传新文件成功

UploadNewFileFailed, // 上传新文件失败

FileExits, // 文件已经存在

RemoteFileBiggerThanLocalFile, // 远程文件大于本地文件

UploadFromBreakSuccess, // 断点续传成功

UploadFromBreakFailed, // 断点续传失败

DeleteRemoteFaild; // 删除远程文件失败

}

public enum DownloadStatus {

RemoteFileNotExist, // 远程文件不存在

DownloadNewSuccess, // 下载文件成功

DownloadNewFailed, // 下载文件失败

LocalFileBiggerThanRemoteFile, // 本地文件大于远程文件

DownloadFromBreakSuccess, // 断点续传成功

DownloadFromBreakFailed; // 断点续传失败

}

}

FtpConfig类:

/**

*

*/

package com.pccw.portlet.publictools;

/**

* FTP配置类

* @author WangXianfeng 1:18:45 PM Jul 16, 2011

*/

public class FtpConfig {

private String server;

private int port;

private String username;

private String password;

private String path;

gets 。。sets。。

}

测试类:

import java.util.List;

import com.pccw.portlet.publictools.FtpConfig;

import com.pccw.portlet.publictools.FtpUtil;

/**

*

* @author WangXianfeng 1:20:45 PM Jul 16, 2011

*/

public class HelloWorld {

/**

* @param args

*/

public static void main(String[] args) throws Exception {

FtpConfig config = new FtpConfig();

config.setServer("192.168.0.199");

config.setPort(21);

config.setUsername("wxf");

config.setPassword("wxf");

config.