zoukankan      html  css  js  c++  java
  • VFS 上传文件到sftp 报错 包含中文路径 或者中文文件名称

    之前用Apache commons-vfs工具进行ftp操作(FTP服务器是 FileZilla Server)

    上传本地文件 到 ftp服务器上,如果文件名称 包含 中文 报错

    org.apache.commons.vfs2.FileSystemException: Could not put FTP file to “e:红黄蓝股价暴跌.docx” to

    sftp://dsideal:***@192.168.1.168/红黄蓝股价暴跌.docx

    1、有可能是 登录FTP用户名没有权限 创建文件 需要登录用户有创建文件的权限

    2、需要 修改编码 从utf-8 到 ISO-8859-1

     private static FileSystemManager fsManager = null;
    	  
    		static {
    			try {
    				fsManager = VFS.getManager();
    			} catch (Exception e) {
    				e.printStackTrace();
    			}
    		}
    //需要 ftp 服务器用户有 添加,修改 删除文件的权限
    
    public void upfile(File file) {
    	try {
    	initConfig();
    	
    	String inFilePath=ftpPathFull;
    	 // Create local file object
    	   FileObject localFile = fsManager.resolveFile(file.getAbsolutePath());
    	   // Create remote file object
    	  String sftpUri=   inFilePath+file.getName();
    	 String  sftpUriiso= new String(sftpUri.getBytes("UTF-8"),"ISO-8859-1");
     FileObject remoteFile = fsManager.resolveFile(sftpUriiso);
    // 如果文件不存在,则创建文件
    			if (!remoteFile.exists()) {
    				remoteFile.createFile();
    			}
    	    remoteFile.copyFrom(localFile, Selectors.SELECT_SELF);
    	    logger.info("上传文件成功:"+file.getName());
    	} catch (Exception e) {
    		e.printStackTrace();
    		logger.error(e.getMessage());
    		logger.error(e.getLocalizedMessage(),e);
    	}
    }
    
    
  • 相关阅读:
    nginx反向代理下没有获取到正确的clientIP问题发散
    TPL概要
    OAuth2:Authorization Flows
    ArrayList部分源码解析
    二分法之通用模板
    Leetcodet题目解析-1 c++版
    git初始用+将git项目上传到github
    参加ACM省赛有感
    杭电acm 1274展开字符串
    杭电acm 1263水果
  • 原文地址:https://www.cnblogs.com/z_lb/p/9967870.html
Copyright © 2011-2022 走看看