惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Scott Helme
Scott Helme
N
Netflix TechBlog - Medium
AI
AI
Security Latest
Security Latest
GbyAI
GbyAI
P
Proofpoint News Feed
Y
Y Combinator Blog
A
Arctic Wolf
G
Google Developers Blog
U
Unit 42
爱范儿
爱范儿
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
Vulnerabilities – Threatpost
Know Your Adversary
Know Your Adversary
Cisco Talos Blog
Cisco Talos Blog
T
Tor Project blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
L
Lohrmann on Cybersecurity
C
CERT Recently Published Vulnerability Notes
C
Check Point Blog
B
Blog RSS Feed
The GitHub Blog
The GitHub Blog
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 【当耐特】
博客园 - Franky
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
C
Cisco Blogs
云风的 BLOG
云风的 BLOG
NISL@THU
NISL@THU
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Microsoft Security Blog
Microsoft Security Blog
T
The Blog of Author Tim Ferriss
阮一峰的网络日志
阮一峰的网络日志
Latest news
Latest news
L
LINUX DO - 最新话题
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
美团技术团队
WordPress大学
WordPress大学
L
LangChain Blog
Stack Overflow Blog
Stack Overflow Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
大猫的无限游戏
大猫的无限游戏
The Hacker News
The Hacker News
Simon Willison's Weblog
Simon Willison's Weblog
V
V2EX
Project Zero
Project Zero
博客园_首页

博客园 - 南郭先生kaka

待处理数据的两种模型 nginx重启无法找到PId的解决办法 Wiki版产品需求---产品需求文档到底是谁的?产品到底是谁的? 为什么说private方法是有罪的 XML2JSON 的【net.sf.json.JSONException: nu.xom.ParsingException must be followed by either attribute specifications, ">" or "/>"】问题解决办法 继承的第一原则 致那些不甘寂寞的人 上传File时,浏览器总是添加<pre>的解决办法 使用XSLT转换XML2XML Java 模拟 Http Post WITH AS SQL语句的用法 【Code Style】多余判断 java.lang.NoClassDefFoundError错误 Spring 中Quartz配置数据库化 FactoryBean在XML中的依赖注入方法 配置CentOS6.3 NFS Bean复制的几种框架性能比较(Apache BeanUtils、PropertyUtils,Spring BeanUtils,Cglib BeanCopier) 重读《目标》---目标 重读《目标》---序
Camel FTP中文目录解决办法
南郭先生kaka · 2013-03-18 · via 博客园 - 南郭先生kaka

         在Camel中使用FTP只需要简单的DSL配置就可以了,把对应的jar放到classpath即可,但是在使用中遇到了FTP服务器上中文目录的问题,如果FTP服务器上的目录是中文的,那么FTP执行什么信息都没有,也没有错误,也没有下载下来。搞得我有些莫名其妙,不知道到底是怎么回事。

         后来开始跟踪Camel源代码进行debug,终于发现在org.apache.camel.component.file.remote.FtpOperations类的doChangeDirectory方法中,无法进入到对应的中文目录。

 1   private void doChangeDirectory(String path) {
 2         if (path == null || ".".equals(path) || ObjectHelper.isEmpty(path)) {
 3             return;
 4         }
 5 
 6         log.trace("Changing directory: {}", path);
 7         boolean success;
 8         try {
 9             if ("..".equals(path)) {
10                 changeToParentDirectory();
11                 success = true;
12             } else {
13                 success = client.changeWorkingDirectory(path);
14             }
15         } catch (IOException e) {
16             throw new GenericFileOperationFailedException(client.getReplyCode(), client.getReplyString(), e.getMessage(), e);
17         }
18         if (!success) {
19             throw new GenericFileOperationFailedException(client.getReplyCode(), client.getReplyString(), "Cannot change directory to: " + path);
20         }
21     }

     关键就在第13行client.changeWorkingDirectory的方法,而这个client是用的org.apache.commons.net.ftp.FTPClient,上网查找了一下,发现很多人都遇到了FTPClient不能进入中文目录的问题。

     尝试了三种方法:

      第一种改变编码,不行,还是不能进入目录。

 uri = new String(uri.getBytes("gb2312"),"iso-8859-1");

     第二种方法,设置表头的编码,还是不行。

.process(new Processor() {
                            
                            @Override
                            public void process(Exchange exchange) throws Exception {
                                exchange.setProperty(Exchange.CHARSET_NAME, "gb2312");
                            }
                        })

   第三种方法,设置FTPClient的编码,这个终于OK了,关键就在最后的红字,ftpClient.controlEncoding=gb2312

String uri = "ftp://username@10.10.XX4.122/中文目录?password=xxxx&ftpClient.controlEncoding=gb2312";