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