- 論壇徽章:
- 0
|
編寫目的
自己寫了個腳本用來打包發(fā)布war但是由于上傳的使用使用的ftp(難道比較原始??),可是每次都要輸入用戶名,密碼。感覺很煩,想了想就是就自己簡單的實現(xiàn)了一個ftp的命令行工具。
可以做撒
與ftp控制臺工具類似
java -jar simpleftpclient.jar --host 203.195.167.55 --userName test --password K~wqYDZpTg2
代碼中調(diào)用
導入 simpleftpclient.jar
FtpUser user = new FtpUser();
user.setAddr(host);
user.setPassword(password);
user.setUserName(userName);
new FtpManager().sendCmd(user,cmd.replace("*"," "));
代碼提交在git 上歡迎查看
http://git.oschina.net/94fzb/simpleftpclient
目前支持命令 dir put get cd exit 這些基礎命令。歡迎完整。。
1.png (66.62 KB, 下載次數(shù): 31)
下載附件
2015-07-13 10:55 上傳
代碼ftp 狀態(tài)碼對應的方法- package com.fzb.ftp;
-
- import java.lang.reflect.Method;
- import java.util.HashMap;
- import java.util.Map;
-
- public class StatusMap {
-
- private static Map<Integer, Method> map = new HashMap<Integer, Method>();
-
- static {
- reloadMap();
- }
-
- private static void reloadMap() {
- try {
- map.put(220, FtpResponseImpl.class.getMethod("connectSucc",
- String.class));
- map.put(331, FtpResponseImpl.class.getMethod("inputPassword",
- String.class));
- map.put(230,
- FtpResponseImpl.class.getMethod("loginSucc", String.class));
- map.put(200, FtpResponseImpl.class.getMethod("initCmdSucc",
- String.class));
- map.put(215, FtpResponseImpl.class.getMethod("modelChanageSucc",
- String.class));
- map.put(227, FtpResponseImpl.class.getMethod("passiveModeSucc",
- String.class));
- map.put(150,
- FtpResponseImpl.class.getMethod("tipsMsg", String.class));
- map.put(226, FtpResponseImpl.class.getMethod("modelChanageSucc",
- String.class));
- map.put(250, FtpResponseImpl.class.getMethod("initCmdSucc",
- String.class));
- map.put(550,
- FtpResponseImpl.class.getMethod("tipsMsg", String.class));
- map.put(500,
- FtpResponseImpl.class.getMethod("tipsMsg", String.class));
- map.put(425,
- FtpResponseImpl.class.getMethod("tipsMsg", String.class));
- map.put(530,
- FtpResponseImpl.class.getMethod("loginFailed", String.class));
-
- } catch (NoSuchMethodException e) {
- e.printStackTrace();
- } catch (SecurityException e) {
- e.printStackTrace();
- }
- }
-
- public static Method getMethod(Integer statusCode) {
- // just for dev
- reloadMap();
- return map.get(statusCode);
- }
- }
復制代碼 |
-
1.png
(66.62 KB, 下載次數(shù): 45)
下載附件
2015-07-13 10:55 上傳
|