public String download(String ftpUrl,String sfzh){
FTPClient ftpClient = new FTPClient();
InputStream inputStream = null;
String re=null;
try {
ftpClient.connect(ftp_ip,ftp_port);
ftpClient.login(ftp_username, ftp_password);
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
//是否成功登录服务器
int reply = ftpClient.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftpClient.disconnect();
}
//跳转到指定目录
ftpClient.changeWorkingDirectory(ftpUrl);
//5.遍历下载的目录
FTPFile[] fs = ftpClient.listFiles();
for (FTPFile ff : fs){
//解决中文乱码问题,两次解码
byte[] bytes=ff.getName().getBytes("iso-8859-1");
String fileName=new String(bytes,"utf-8");
if(sfzh.equals(fileName)){
inputStream = ftpClient.retrieveFileStream(fileName);
}
} if (inputStream != null) {
byte[] data=null;
data=new byte[inputStream.available()];
BASE64Encoder encoder=new BASE64Encoder();
re=encoder.encode(data);
}
} catch (Exception e) {
e.printStackTrace();
}finally{
if(ftpClient.isConnected()){
try{
ftpClient.disconnect();
}catch(IOException e){
e.printStackTrace();
}
}
if(null != inputStream){
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} return re;
}

  

最新文章

  1. 【转】Web Service单元测试工具实例介绍之SoapUI
  2. css004 用样式继承节省时间
  3. codeforces 540B.School Marks 解题报告
  4. 3种归并操作js代码
  5. Oracle表变化趋势追踪记录
  6. 前端笔试题目总结——应用JavaScript函数递归打印数组到HTML页面上
  7. Android设备的ID
  8. css+js整站变灰(兼容IE7+)
  9. 发票OCR识别/票据OCR自动识别
  10. Python学习笔记2
  11. [bzoj1910] [Ctsc2002] Award 颁奖典礼
  12. AJAX+jQuery+ASP实现实时验证身份证信息是否已存在---人事系统
  13. C# 之 static的用法详解
  14. 用 python 写一个年会抽奖小程序
  15. vue引入css的两种方式
  16. Syncfusion SfDataGrid 导出Excel
  17. centor os 安装nginx
  18. 【洛谷 P3203】 [HNOI2010]弹飞绵羊(LCT)
  19. tomcat做成服务
  20. MySQL工作经验

热门文章

  1. 【BZOJ4552】排序(线段树,二分)
  2. es6 字符串 对象 拓展 及 less 的语法
  3. scala Futures and Promises
  4. 使用 apt-get 清理
  5. UVA 122 -- Trees on the level (二叉树 BFS)
  6. electron创建窗口常用配置参数
  7. Git-Runoob:Git 服务器搭建
  8. 自定义View等级滑动条的实现
  9. [VBA]合并工作簿优化版
  10. Python_List对象内置方法详解