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目录下另一个文件夹下创建对应的空文件,听说是为了文件的完整性,既然这么说,那么就必 ...
随机推荐
- Alpha冲刺(七)
Information: 队名:彳艮彳亍团队组长博客:戳我进入作业博客:班级博客本次作业的链接 Details: 组员1(组长)柯奇豪 过去两天完成了哪些任务 改用更易用的springboot+myb ...
- gitlab发送邮件配置
在使用gitlab过程中,通常需配置邮件来实现代码管理服务器向成员(member)发送邮件.本文将实现gitlab中邮件配置 1.编辑 /etc/gitlab/gitlab.rb,修改配置邮件,这里以 ...
- ssm集合的配置
web.xml <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&quo ...
- Python 数据分析—第九章 数据聚合与分组运算
打算从后往前来做笔记 第九章 数据聚合与分组运算 分组 #生成数据,五行四列 df = pd.DataFrame({'key1':['a','a','b','b','a'], 'key2':['one ...
- Verilog MIPS32 CPU(三)-- ALU
Verilog MIPS32 CPU(一)-- PC寄存器 Verilog MIPS32 CPU(二)-- Regfiles Verilog MIPS32 CPU(三)-- ALU Verilog M ...
- Exception has been thrown by the target of an invocation
I'd suggest checking for an inner exception. If there isn't one, check your logs for the exception t ...
- 判断客户端是iOS还是Android,判断是不是在微信浏览器打开
bool flag = false; string agent = System.Web.HttpContext.Current.Request.UserAgent.ToLower(); string ...
- Windows上编译libjpeg
通常libjpeg可以使用如下命令行生成Visual Studio 2010的项目文件: nmake /f makefile.vc setup-v10 但可惜我们使用的是Visual Studio 2 ...
- 【08】循序渐进学 docker:docker compose
写在前面的话 在之前的操作中,即使是单个容器每次都需要敲很长的命令,当需要多个容器组合着用的时候更加麻烦,此时我们急需找到一种一次配置,随便运行的方法. 这就是这一节重点,单机容器编排工具:docke ...
- L365
When I started my company nine years ago, I was a young, inexperienced founder without much capital. ...