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);
    	}
    }
    
    
  • 相关阅读:
    raspbian设置locale
    docker redis
    consul开发部署集群
    自动更新ssh登录的key到远程主机
    docker官方脚本阿里云镜像
    nodejs中国镜像
    github修改hosts加速
    docker容器更新总是自动重启
    webstrom不显示右边的竖线,代码结构线
    _mssql.c:266:22: fatal error: sqlfront.h: No such file or directory
  • 原文地址:https://www.cnblogs.com/z_lb/p/9967870.html
Copyright © 2011-2022 走看看