环境:VSFTP+FTPClient+Client
使用FTPClient上传文件的时候总是卡住,而且文件大小为0,上传失败,
解决方案:
添加代码:调用FTPClient的enterLocalPassiveMode();方法,设置为被动模式,既可以解决。
//FTPClient 的使用
public void FTPClientTest() throws Exception {
//创建 FTPClient 对象
FTPClient ftp = new FTPClient();
//链接 端口使用的 21
ftp.connect("169.254.18.16", 21);
//给定用户名与密码,链接时完成登录
ftp.login("ftpuser", "ftpuser");
ftp.enterLocalPassiveMode();
//操作上传文件
InputStream is = new
FileInputStream("d:/java.jpg");
//指定上传文件的保存目录
ftp.changeWorkingDirectory("/home/ftpuser/casual");
//开启字节流传输
ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
//文件上传
boolean b = ftp.storeFile("aa.jpg", is);
System.out.println(b);
//退出登录
ftp.logout();
}
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有