- 论坛徽章:
- 0
|
编写目的
自己写了个脚本用来打包发布war但是由于上传的使用使用的ftp(难道比较原始??),可是每次都要输入用户名,密码。感觉很烦,想了想就是就自己简单的实现了一个ftp的命令行工具。
可以做撒
与ftp控制台工具类似
java -jar simpleftpclient.jar --host 203.195.167.55 --userName test --password K~wqYDZpTg2
代码中调用
导入 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 这些基础命令。欢迎完整。。
代码ftp 状态码对应的方法- 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, 下载次数: 44)
|