由于公司的业务,需要讲ftp的文件进行定时批量的下载以及上传,先是将一百多万的文件下载之后进行一个小的编辑,然后再将文件上传上午,其中遇到了许多的问题,
为了形成一个备忘录,所以记着,或许对你们也有点帮助
/**
*
* 从ftp中下载文件
*
* @param ftppath
* 文件的路径
* @param fawenr
* 发文日期
* @param tongzhislx
* 表格代码 用于生成文件夹格式
*
* @return 返回的是压缩文件地址
*/
public String downFromftpAndZip(String ftpPath, String fawenr,
String tongzhislx) {
File file = null;
FTPClient client = new FTPClient();
FileOutputStream os = null;
String saveDir = "";
System.out.println("ftp的下载地址为:" + ftpPath);
if (ftpPath != null && ftpPath.length() > 0) {
int st = ftpPath.indexOf(":");
int index = st + 1 + ftpPath.substring(st + 1).indexOf(":");
int ipIndex = ftpPath.indexOf("@");
int portIndex = ftpPath.lastIndexOf(":");
// 下载的文件存放路径
String ftpUser = ftpPath.substring(st + 3, index); // "efs";
// UserName
String ftpPwd = ftpPath.substring(index + 1, ipIndex); // "efs";
// Password
String hostname = ftpPath.substring(ipIndex + 1, portIndex); // "10.50.161.9";//截取获得
// host
String str = ftpPath.substring(portIndex);
int dirIndex = str.indexOf("/");
int port = Integer.parseInt(ftpPath.substring(portIndex + 1,
dirIndex + portIndex));// 21;
saveDir = getDateFormat(fawenr);// 转为相应的时间格式
try {
logger.info("before connect connect state:"
+ client.isConnected());
client.connect(hostname, port);// 连接ftp
logger.info("