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目录下另一个文件夹下创建对应的空文件,听说是为了文件的完整性,既然这么说,那么就必 ...
随机推荐
- 敏捷软件开发:原则、模式与实践——第11章 DIP:依赖倒置原则
第11章 DIP:依赖倒置原则 DIP:依赖倒置原则: a.高层模块不应该依赖于低层模块.二者都应该依赖于抽象. b.抽象不应该依赖于细节.细节应该依赖于抽象. 11.1 层次化 下图展示了一个简单的 ...
- 9.29学习的js基础
js基础 1.三种js引入方式 a).<input type="button" value="点击事件" onClick="documen ...
- 第十六章 IIC协议详解+UART串口读写EEPROM
十六.IIC协议详解+Uart串口读写EEPROM 本文由杭电网友曾凯峰根据小梅哥FPGA IIC协议基本概念公开课内容整理并最终编写Verilog代码实现使用串口读写EEPROM的功能. 以下为原文 ...
- APUE(7)---进程环境
一.main函数 C程序总是从main函数开始执行.main函数的原型是: int main(int argv, char *argv[]); 当内核执行C程序时,在调用main前先调用一个特殊的启动 ...
- 基于Qt5 跨平台应用开发
1.Qt简介 2.Qt 编程关键技术 2.1 信号与槽 2.2 Qt事件处理 3.Qt开发与实例分析 3.1 开发环境 3.2 系统实现基本框架 3.3 数据库管理 3.5 对Excel进行操作 4. ...
- [LeetCode 题解]: Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...
- python读写Excel文件(xlrd、xlwr)
一.首先需要安装第三方库:pip install xlrd 1.打开Excel文件,由于写入时需要copy,所以这里加上保留原格式参数:formatting_info=True excel_file ...
- (zxing.net)一维码Code 39的简介、实现与解码
一.简介 一维码Code 39:由于编制简单.能够对任意长度的数据进行编码.支持设备广泛等特性而被广泛采用. Code 39码特点: 能够对任意长度的数据进行编码,其局限在于印刷品的长度和条码阅读器的 ...
- C#多线程学习(二) 如何操纵一个线程
在C#中,线程入口是通过ThreadStart代理(delegate)来提供的,你可以把ThreadStart理解为一个函数指针,指向线程要执行的函数,当调用Thread.Start()方法后,线程就 ...
- table数据跑马灯效果
1.使用marquee标签实现普通文本字符串跑马灯效果. <marquee behavior="scroll" scrollamount="3" styl ...