FTP通用处理(二)

2014-11-24 09:14:46 · 作者: · 浏览: 1
on
*/
public FTPFile[] getFileNameList() throws IOException, FTPException, ParseException
{
FTPFile[] fileList= ftpClient.dirDetails(FTP_information.getThis().getFTP_UP_URL());
ftpClient.chdir(FTP_information.getThis().getFTP_UP_URL());
return fileList;
}
/**
* 下载文件夹
* @param saveDir
*/
public void Download(String saveDir)
{
try {
if(ConnectionFTP())
{
FTPFile[] list=getFileNameList();
File file=new File(saveDir);
if (!file .exists() && !file .isDirectory())
{
file .mkdir();
}
for (FTPFile FileName : list) {
if (FileName.isFile()) {
ftpClient.get(saveDir,FileName.getName());
logger.debug("下载文件:"+FileName.getName()+"完成");
}
}
logger.debug("当前所在文件夹:"+FTP_information.getThis().getFTP_UP_URL()+"下载完成");
ftpClient.quit();
}
} catch (IOException e) {
logger.error(e);
} catch (FTPException e) {
logger.error(e);
} catch (ParseException e) {
logger.error(e);
}
}
/**
*

删除ftp上的文件


*/
public boolean removeFile(String srcFname){
if(ftpClient.connected()){
try {
if(ftpClient.existsFile(srcFname))
{
ftpClient.delete(srcFname);
}
else
{
logger.debug("不存在需要删除的文件");
}
return true;
} catch (Exception e) {
logger.error("FTP删除文件出现异常:",e);
this.closeCon();
}
}
return false;
}
/**
*

销毁ftp连接


*/
public void closeCon(){
if(ftpClient.connected()){
try {
ftpClient.quit();
} catch (Exception e) {
logger.error("FTP断开连接失败:",e);
}
}
}
}