/**
日志
*/
private static final Log log = LogFactory.getLog(ftcClients.class);
//FTC连接地址
public static final String URL=ApplicationPropertiesHolder.getProperty("docInterface.ftp.url");
//FTC连接端口
public static final int PORT=Integer.parseInt(ApplicationPropertiesHolder.getProperty("docInterface.ftp.post"));
//FTC账号
public static final String USERNAME=ApplicationPropertiesHolder.getProperty("docInterface.ftp.userName");
//FTC密码
public static final String PASSWORD=ApplicationPropertiesHolder.getProperty("docInterface.ftp.passWord");
//图片存放文件夹
public static final String IMAGESRC=ApplicationPropertiesHolder.getProperty("docInterface.ftp.directoryString");
public static List SubmitPost(Map imges){
List patch=new ArrayList();
FTPClient ftp = new FTPClient();
try {
ftp.connect(URL, PORT); //连接
boolean isLogin = ftp.login(USERNAME, PASSWORD); //登陆
System.out.println("fcp登录:"+isLogin);
ftp.setFileType(FTPClient.BINARY_FILE_TYPE); //设置传输文件类型
// boolean chang= ftp.changeWorkingDirectory(IMAGESRC);//设置传输文件存放文件夹
String pacthString=getpacth();
if(!mkdirs(ftp,pacthString)){//创建目录
return patch;
}
ftp.setControlEncoding("utf-8");
ftp.enterLocalPassiveMode();//设置为主动模式
File file_in=null;
InputStream is=null;
BufferedInputStream inStream = null;
for (Map.Entry imge : imges.entrySet()) {
file_in = new File(imge.getValue());
log.info(imge.getKey()+"文件存在于否:"+file_in.exists());
is = new FileInputStream(file_in);
inStream = new BufferedInputStream(is);
boolean result = ftp.storeFile(new String(imge.getKey().getBytes("utf-8"),"iso-8859-1"), inStream);
log.info(imge.getKey()+"文件传输:"+result+"传输地址:"+pacthString+"/"+imge.getKey());
if(!result){
is.close();
patch.add(null);
return patch;
}else{
patch.add(pacthString+"/"+imge.getKey());
}
}
is.close();
ftp.logout();
return patch;
} catch (Exception e) {
log.info(e.getMessage());
e.printStackTrace();
return patch;
}
} 这是我写的测试通过的 不知道是不是编码导致你上次不上去了