nginx - Java上传文件到ftp文件为0k,求帮忙!
天蓬老师
天蓬老师 2017-04-18 10:38:06
[Java讨论组]
天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

全部回复(2)
PHP中文网

代码本身没有问题 你试一下使用FTP工具可以不?或者完全关闭防火墙试一下
service iptables stop

伊谢尔伦

/**

  • 日志
    */

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<String> SubmitPost(Map<String,String> imges){

 List<String> patch=new ArrayList<String>();
    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<String, String> 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;
              }  
                 
            
       }          这是我写的测试通过的    不知道是不是编码导致你上次不上去了
       
       
       
       
       
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号