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);
    	}
    }
    
    
  • 相关阅读:
    【HDU 2874】Connections between cities(LCA)
    【Gym 100947C】Rotate It !!
    【CodeForces 615E】Hexagons
    Course Selection CodeChef
    UVA 10779 Collectors Problem[最大流]
    1855: [Scoi2010]股票交易[单调队列优化DP]
    1854: [Scoi2010]游戏[并查集]
    1853: [Scoi2010]幸运数字[容斥原理]
    poj3233 Matrix Power Series
    3969 [Mz]平方和【斐波那契平方和】
  • 原文地址:https://www.cnblogs.com/z_lb/p/9967870.html
Copyright © 2011-2022 走看看