ftp发送文件包括中文名
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发送文件包括中文名的更多相关文章
- ftp发送文件
#!/bin/bash #author:luyongjin IP=220.250.65.22 USERNAME='ftp_hangye20' PASSWORD='oUo2JD7oK#u-epw' #D ...
- python网络编程-socket上传下载文件(包括md5验证,大数据发送,粘包处理)
ftp server 1) 读取文件名 2)检查文件是否存在 3)打开文件 4)检查文件大小 5)发送文件大小给客户端 6)等客户端确认 7)开始边读边(md5计算)发数据 8)给客户端发md5 ft ...
- ftp (文件传输协议)
ftp (文件传输协议) 锁定 本词条由“科普中国”百科科学词条编写与应用工作项目 审核 . FTP 是File Transfer Protocol(文件传输协议)的英文简称,而中文简称为“文传协议” ...
- FTP远程文件传输命令
使用ftp命令进行远程文件传输 ftp命令是标准的文件传输协议的用户接口.ftp是在TCP/IP网络上的计算机之间传输文件的简单有效的方法.它允许用户传输ASCII文件和二进制文件. 在ftp会话过程 ...
- [转]C#网络编程(订立协议和发送文件) - Part.4
本文转自:http://www.tracefact.net/CSharp-Programming/Network-Programming-Part4.aspx 源码下载:http://www.trac ...
- python ftp 传输文件
# -*- coding: utf-8 -*- # 本地bytes 数据上报服务器同时创建文件from ftplib import FTP import time, _io from constant ...
- ASP.NET MVC 向浏览器发送文件以提供文件下载功能
撑到大三了,结果发现周围的同学更加堕落了,尤其是某些人,表面上看起来很认真,实际上三天打鱼,两天晒网,结果一事无成,却还要抱怨学校教育失败. 为了吸取他们的教训,就算是一个小小的编码问题,我也要努力解 ...
- C#网络编程(订立协议和发送文件) - Part.4
文件传输 前面两篇文章所使用的范例都是传输字符串,有的时候我们可能会想在服务端和客户端之间传递文件.比如,考虑这样一种情况,假如客户端显示了一个菜单,当我们输入S1.S2或S3(S为Send缩写)时, ...
- c# ftp创建文件(非上传文件)
c# ftp创建文件(非上传文件) 一.奇葩的故事: 今天项目中遇到这么个奇葩的问题,ftp文件传输完成后要在ftp目录下另一个文件夹下创建对应的空文件,听说是为了文件的完整性,既然这么说,那么就必 ...
随机推荐
- 《深入理解Elasticsearch》README
书目 <深入理解ElasticSearch>拉斐尔·酷奇,马雷克·罗戈任斯基[著]张世武,余洪森,商旦[译] 机械工业出版社,2016.1 本系列包括以下8篇笔记 第01章 Elastic ...
- memcached整理の编译
memcached是一个自由&开放源码, 高性能,分布式的内存对象缓存系统. nosql相对于传统关系型数据库的"行与列",NoSQL 的鲜明特点为k-v 存储(memca ...
- You must restart adb and Eclipse.
打开Eclipse运行android 程序发现虚拟机启动不了提示 You must restart adb and Eclipse. 如下方式适用于端口占用的情况: 1.netstat -ano|f ...
- Partition--分区切换2
有分区表TB2和TB2_History CREATE TABLE TB2( ID BIGINT IDENTITY(1,1) PRIMARY KEY, C1 NVARCHAR(200))ON[ps_T ...
- 【windows】dos命令查看某个文件夹下所有文件目录列表
dos命令 dir展示一个目录中的文件夹和文件列表 /a代表显示隐藏目录
- 【RabbitMQ学习记录】- 消息队列存储机制源码分析
本文来自 网易云社区 . RabbitMQ在金融系统,OpenStack内部组件通信和通信领域应用广泛,它部署简单,管理界面内容丰富使用十分方便.笔者最近在研究RabbitMQ部署运维和代码架构,本篇 ...
- Hibernate Update方法提交错误
最近用通用Dao更新对象,报了以下错误 Row was updated or deleted by another transaction (or unsaved-value mapping was ...
- centos有两个版本的apache
service服务链接更新 cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd
- KVM 安装 VMware 虚拟机
去掉了“双引号”改为:vmx.allowNested = TRUE 打开在其中创建虚拟机的文件夹VMDISK和搜索与您的虚拟机的名称. vmx 文件. 用记事本打开它,并添加上述条目. 所以 vmx. ...
- jquery事件一 ---鼠标移入移出
比较一下几个jquery事件的区别 mouseover() 鼠标进入(进入子元素也触发) mouseout() 鼠标离开(离开子元素也触发) mouseenter() 鼠标进入(进入子元素不触发) m ...