java ftp 下载 0k_Java上传文件到ftp文件为0k,求帮忙!

该博客给出了一段Java代码,用于实现FTP文件上传功能。代码中定义了FTP连接地址、端口、账号、密码等信息,通过FTPClient类进行连接、登录,设置传输文件类型和工作目录,创建目录,最后将文件上传到指定位置,并处理异常情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/**

日志

*/

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;

}

} 这是我写的测试通过的 不知道是不是编码导致你上次不上去了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值