最近因工作需要,数据库中的数据需要从FTP服务中抽取数据文件然后校检再抽取到数据中。因为第一步需要从FTP服务中抽取数据文件。第二步采用JDBC批量数据更新。
1。采用Apache.FTPClient:
Java代码
1. /**
2. * Apache.FTPClient FTP操作共公类
3. *
4. * @author 张明学
5. *
6. */
7. public class FTPCommon {
8.
9. private FTPClient ftpClient;
10.
11. private FTPModel ftpModel;
12.
13. public FTPCommon(FTPModel ftp) {
14. super();
15. // 从配置文件中读取初始化信息
16. this.ftpClient = new FTPClient();
17. this.ftpModel = ftp;
18. }
19.
20. /**
21. * 连接并登录FTP服务器
22. *
23. */
24. public boolean ftpLogin() {
25. boolean isLogin = false;
26. FTPClientConfig ftpClientConfig = new FTPClientConfig(
27. FTPClientConfig.SYST_NT);
28. ftpClientConfig.setServerTimeZoneId(TimeZone.getDefault().getID());
29. this.ftpClient.setControlEncoding("GBK");
30. this.ftpClient.configure(ftpClientConfig);
31. try {
32. if (this.ftpModel.getPort() > 0) {
33. this.ftpClient.connect(ftpModel.getUrl(), ftpModel.getPort());
34. } else {
35. this.ftpClient.connect(ftpModel.getUrl());
36. }
37. // FTP服务器连接回答
38. int reply = this.ftpClient.getReplyCode();