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. javascript总结26:Date

    1 获取Date对象 Date-引用类型,JavaScript中的内置对象 获取当前时间 var date = new Date(); //UTC的时间 //返回数字,时间的毫秒形式 var date ...

  2. page next page prev

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...

  3. 编写高质量代码改善C#程序的157个建议——建议84:使用PLINQ

    建议84:使用PLINQ LINQ最基本的功能就是对集合进行遍历查询,并在此基础上对元素进行操作.仔细推敲会发现,并行编程简直就是专门为这一类应用准备的.因此,微软专门为LINQ拓展了一个类Paral ...

  4. ArcGIS API for Javascript 图层切换渐变效果实现

    在一个WebGIS系统中往往要实现图形的切换,比如业务图层的切换,以及底图的切换等等,可以通过控制图层的可见性来实现.比如通过设置图层的opacity .visible来控制,前几天有网友聊天的时候提 ...

  5. Android-ContentProvider-UriMatcher

    注意:在ContentProvider里面写对数据库增删改查的时候,千万不能 db.close();  cursor.close(); 等操作,不然其他应用访问不到数据,也没有必要写isOpen(); ...

  6. 关于Relay的麻烦之处

    问题背景 由于QueryRender是直接将数据塞进Render()里的 handleUpdate = (hasNextPage, xdata) =>{ console.log(3); cons ...

  7. Android应用开发以及设计思想深度剖析

    Android应用开发以及设计思想深度剖析(1) 21cnbao.blog.51cto.com/109393/956049

  8. Python操作配置文件configparser模块

    在实际的开发过程中,我们常有操作ini格式和conf格式配置文件的操作,Python为我们提供了configparser模块,方便我们对配置文件进行读写操作. config.ini配置文件内容如下: ...

  9. Weekly Contest 121

    984. String Without AAA or BBB Given two integers A and B, return any string S such that: S has leng ...

  10. ocp题库变化,052新加的考试题及答案整理-32

    32. Examine these commands and their output: • SQL> SELECT * FROM emp; • ENO ENAME • ---- ----- • ...