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);
    	}
    }
    
    
  • 相关阅读:
    leetcode 141 环形链表
    [转载]Tensorflow中reduction_indices 的用法
    SIFT特征原理与理解
    numpy切片和布尔型索引
    IPython的使用
    [文献阅读]基于卷积神经网络的高光谱图像深度特征提取与分类
    验证码校验
    防止表单重复提交
    MyBatis 一对一,一对多,多对多
    MySQL基础内容
  • 原文地址:https://www.cnblogs.com/z_lb/p/9967870.html
Copyright © 2011-2022 走看看