public void sendwordToftp() {
        try {
            Json json = new Json();
            String fileName = getRequest().getParameter("url");
            fileName = fileName.substring(fileName.indexOf("=") + 1);
            String remotePath = ConfigReadUtil.getInstance().getConfigItem(
                    "FileSavePath")
                    + "/" + fileName;
            List<Ftpconfig> ftpList = ftpManager.getFtpByName("景点预报");
            for (Ftpconfig ftp : ftpList) {
                String ip = ftp.getIp();
                String port = ftp.getPort();
                String username = ftp.getUsername();
                String password = ftp.getPassword();
                String inpath = ftp.getInpath();
                String outpath = ftp.getOutpath();
                boolean flag = connect(inpath, ip, port, username, password);
                if (flag) {
                    if (inpath.startsWith("//")) { // 共享目录
                        List<String> fileNames = TrvalSavedAction
                                .getFileNamesFromSmb("smb:" + remotePath);
                        for (String name : fileNames) {
                            String localFile = "D:/Temp";
                            File f = new File(localFile);
                            if (!f.exists()) {
                                f.mkdirs();
                            }
                            File file = TrvalSavedAction.readFromSmb("smb:"
                                    + remotePath.trim() + name, localFile);
                            upload(file, inpath);
                        }
                    } else {
                        File file = new File(remotePath);
                        upload(file, inpath);
                    }
                }
            }

} catch (Exception e) {
            e.printStackTrace();
        }
    }

private boolean connect(String inpath, String ip, String port,
            String username, String password) {
        boolean result = false;
        try {
            ftp = new FTPClient();
            int reply;
            int p = Integer.parseInt(port);
            ftp.connect(ip, p);
            ftp.login(username, password);
            ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
            reply = ftp.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                ftp.disconnect();
                return result;
            }
            ftp.changeWorkingDirectory(inpath);
            result = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;

/**
     *
     * @param file
     *            上传的文件或文件夹
     * @param localPath
     *            服务器上的路径
     * @throws Exception
     */
    private void upload(File file, String localPath) throws Exception {
        if (file.isDirectory()) {
            String[] files = file.list();
            for (int i = 0; i < files.length; i++) {
                File file1 = new File(file.getPath() + "\\" + files[i]);
                String fileName = file1.getName();
                String filePath = file1.getAbsolutePath();
                if (file1.isDirectory()) {
                    upload(file1, localPath);
                    ftp.changeToParentDirectory();
                } else {
                    File file2 = new File(localPath + "\\" + files[i]);
                    FileInputStream input = new FileInputStream(file2);
                    // \test\新建文本文档.txt
                    // \test\01.docx
                    ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
                    String name = new String(file2.getName().getBytes("GB2312"),"ISO-8859-1");
                    ftp.storeFile(file2.getName(), input);
                    input.close();
                }
            }
        } else {
            File file2 = new File(file.getPath());
            FileInputStream input = new FileInputStream(file2);
            ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
            String name = new String(file2.getName().getBytes("GB2312"),"ISO-8859-1");
            ftp.storeFile(name, input);
            input.close();
        }
    }

ftp发送文件包括中文名的更多相关文章

  1. ftp发送文件

    #!/bin/bash #author:luyongjin IP=220.250.65.22 USERNAME='ftp_hangye20' PASSWORD='oUo2JD7oK#u-epw' #D ...

  2. python网络编程-socket上传下载文件(包括md5验证,大数据发送,粘包处理)

    ftp server 1) 读取文件名 2)检查文件是否存在 3)打开文件 4)检查文件大小 5)发送文件大小给客户端 6)等客户端确认 7)开始边读边(md5计算)发数据 8)给客户端发md5 ft ...

  3. ftp (文件传输协议)

    ftp (文件传输协议) 锁定 本词条由“科普中国”百科科学词条编写与应用工作项目 审核 . FTP 是File Transfer Protocol(文件传输协议)的英文简称,而中文简称为“文传协议” ...

  4. FTP远程文件传输命令

    使用ftp命令进行远程文件传输 ftp命令是标准的文件传输协议的用户接口.ftp是在TCP/IP网络上的计算机之间传输文件的简单有效的方法.它允许用户传输ASCII文件和二进制文件. 在ftp会话过程 ...

  5. [转]C#网络编程(订立协议和发送文件) - Part.4

    本文转自:http://www.tracefact.net/CSharp-Programming/Network-Programming-Part4.aspx 源码下载:http://www.trac ...

  6. python ftp 传输文件

    # -*- coding: utf-8 -*- # 本地bytes 数据上报服务器同时创建文件from ftplib import FTP import time, _io from constant ...

  7. ASP.NET MVC 向浏览器发送文件以提供文件下载功能

    撑到大三了,结果发现周围的同学更加堕落了,尤其是某些人,表面上看起来很认真,实际上三天打鱼,两天晒网,结果一事无成,却还要抱怨学校教育失败. 为了吸取他们的教训,就算是一个小小的编码问题,我也要努力解 ...

  8. C#网络编程(订立协议和发送文件) - Part.4

    文件传输 前面两篇文章所使用的范例都是传输字符串,有的时候我们可能会想在服务端和客户端之间传递文件.比如,考虑这样一种情况,假如客户端显示了一个菜单,当我们输入S1.S2或S3(S为Send缩写)时, ...

  9. c# ftp创建文件(非上传文件)

    c#  ftp创建文件(非上传文件) 一.奇葩的故事: 今天项目中遇到这么个奇葩的问题,ftp文件传输完成后要在ftp目录下另一个文件夹下创建对应的空文件,听说是为了文件的完整性,既然这么说,那么就必 ...

随机推荐

  1. SpringMVC源码解读 - RequestMapping注解实现解读 - RequestMappingInfo

    使用@RequestMapping注解时,配置的信息最后都设置到了RequestMappingInfo中. RequestMappingInfo封装了PatternsRequestCondition, ...

  2. Spring实战-README.md

    教程 <Spring实战>(第四版),[美]Craig Walls著,张卫滨译 人民邮电出版社,2016.4 本系列博文包括: 第01章-Spring之旅 第02章-装配Bean 第03章 ...

  3. servlet及xml文件处理流程

    启动项目----会找到web.xml文件---跳转到默认jsp----页面重定向----转到xml.文件下 通过<servlet-mapping>映射找到<servlet>标签 ...

  4. linux安装memcache及memcache扩展

    一.安装libevent# wget http://www.monkey.org/~provos/libevent-2.0.12-stable.tar.gz# tar zxf libevent-2.0 ...

  5. Qt自动填写表单并点击按钮,包括调用js方法

    本篇博客参阅了很多其他大牛的文章,具体找不到了,还望包涵>_< 因为其他博客大都是只有主要代码,对于像我这种菜鸟,根本摸不着头脑,以此想总结一下,帮助新手尽快实现功能... 主要是调用了C ...

  6. Nginx使用

    1. 基本使用 分linux和windows版 windows版可以直接双击exe运行,默认配置为80端口,只有两个页面 html目录下为页面.css.js等代码文件 conf目录下为配置文件 主要的 ...

  7. windows 多个人同时远程同一台电脑

    windows  多个人同时远程同一台电脑 第一步:(内外远程) 参考内网多个人同时远程一台电脑: http://www.cnblogs.com/zlp520/p/7688984.html 第二步:( ...

  8. 网易严选的wkwebview测试之路

    本文来自网易云社区 作者:孙娇 UIWebView是苹果继承于UIView封装的一个加载web内容的类,它可以加载任何远端的web数据展示在你的页面上,你可以像浏览器一样前进后退刷新等操作.不过苹果在 ...

  9. 关于C#低版本升级高版本时,项目中引用Microsoft.Office.Interop.Word,程序提示不存在类型或命名空间名office.

    Report.cs里using Microsoft.Office.Interop.Word;就会报错:编译器错误消息: CS0234: 命名空间“Microsoft.Office”中不存在类型或命名空 ...

  10. “全栈2019”Java第六十八章:外部类访问内部类成员详解

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...