怎么通过TFTP或FTP方式收集配置数据!! 怎么通过TFTP或FTP方式收集配置数据!!给点思路就可以!谢谢各位先辈了!小弟在这谢谢了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在网上找个FTP开源jar包,学习其用法即可。先把配置数据序列化到一个文件里,上传该文件即可。as:import cz.dhl.ftp.Ftp;import cz.dhl.ftp.FtpConnect;import cz.dhl.ftp.FtpFile;import cz.dhl.io.CoFile;import cz.dhl.io.CoLoad;import cz.dhl.io.LocalFile;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import java.io.File;import java.io.IOException;public class FileServer { private static final Log LOG = LogFactory.getLog(FileServer.class); private static FileServer instance; public static FileServer getInstance() { if (instance == null) { instance = new FileServer(); } return instance; } // 文件服务器的绝对路径 private String fileServerDir; private FileServer() { } /** * 获取文件服务器的绝对路径 */ public String getFileServerDir() { return fileServerDir; } public static String getFullPath(String parent, String fileName) { File file = new File(parent, fileName); return file.getAbsolutePath(); } public static void list(String host, String username, String passwd) { // host = ftp.datangmobile.com; // path = pub; // user = anonymous (default); // port = 21 (default); */ FtpConnect cn = FtpConnect.newConnect(host); cn.setHostName(host); cn.setPathName("c:\\"); // Guest login ok, send your password cn.setUserName(username); cn.setPassWord(passwd); Ftp cl = new Ftp(); try { // connect & login to host if(!cl.connect(cn)){ LOG.info("连接FTP服务器失败,三秒后再次尝试连接!"); try { Thread.sleep(3000); } catch (InterruptedException e) { LOG.error("FTP三秒尝试中断过程中出现异常!", e); } LOG.info("再次尝试连接到FTP服务器."); cl.connect(cn); } // get current directory CoFile dir = new FtpFile(cl.pwd(), cl); // list & print current directory CoFile fls[] = dir.listCoFiles(); if (fls != null) { for (CoFile fl : fls) { System.out.println(fl.getName() + (fl.isDirectory() ? "/" : "")); } } } catch (IOException e) { LOG.error("FTP ERROR!", e); } finally { // disconnect from server this must be always run cl.disconnect(); } } public static boolean upload(String host, String username, String passwd, String path, String name, String remoteName) { // host = ftp.datangmobile.com; // path = pub; // user = anonymous (default); // port = 21 (default); */ FtpConnect cn = FtpConnect.newConnect(host); cn.setHostName(host); //cn.setPathName("abc"); cn.setUserName(username); cn.setPassWord(passwd); Ftp cl = new Ftp(); int connectNum=0; try { // connect & login to host while(!cl.connect(cn)){ LOG.info("连接FTP服务器失败,三十秒后再次尝试连接!"); if(connectNum++>=5){ LOG.info("累计尝试连接FTP已达五次,连接失败."); return false; } try { Thread.sleep(30000); } catch (InterruptedException e) { LOG.error("FTP三十秒尝试中断过程中出现异常!", e); } LOG.info("再次尝试连接到FTP服务器......."); } // source FtpFile remote file CoFile file = new FtpFile(remoteName, cl); // destination LocalFile CoFile to = new LocalFile(path, name); // 上传 CoLoad.copy(file, to); // 上载 //CoLoad.copy(to,file); } catch (IOException e) { LOG.error("FTP ERROR!", e); } finally { cl.disconnect(); } return true; } public static void download(String host, String username, String passwd, String path, String name, String remoteName) { // host = ftp.datangmobile.com; // path = pub; // user = anonymous (default); // port = 21 (default); */ FtpConnect cn = FtpConnect.newConnect(host); cn.setHostName(host); //cn.setPathName("abc"); cn.setUserName(username); cn.setPassWord(passwd); Ftp cl = new Ftp(); try { // connect & login to host cl.connect(cn); // source FtpFile remote file CoFile file = new FtpFile(remoteName, cl); // destination LocalFile CoFile to = new LocalFile(path, name); // 下载 CoLoad.copy(to,file); } catch (IOException e) { LOG.error("FTP ERROR!", e); } finally { cl.disconnect(); } } public static void delete(String host, String username, String passwd, String path, String name, String remoteName) { // host = ftp.datangmobile.com; // path = pub; // user = anonymous (default); // port = 21 (default); */ FtpConnect cn = FtpConnect.newConnect(host); cn.setHostName(host); //cn.setPathName("abc"); cn.setUserName(username); cn.setPassWord(passwd); Ftp cl = new Ftp(); try { // connect & login to host cl.connect(cn); // source FtpFile remote file CoFile[] file = new FtpFile[]{new FtpFile(remoteName, cl)}; //删除 CoLoad.delete(file); } catch (IOException e) { LOG.error("FTP ERROR!", e); } finally { cl.disconnect(); } }} 一个能否用设计模式的问题 关于setBounds()方法代码放置位置和图片的读入问题~! Java 5 如何在安钮事件中使电脑喇叭响起来呢? 关于键盘事件 jdbc odbc 疑问? 初学者,关于BufferedReader输入流的问题 急!急!急!!JAVA jdk环境变量设置半天都没有好 不知道怎么回事。大虾门帮忙。。 Servlet 问题(高手帮忙) SOS!!!!!!!!!!!!!!SOS 网络编程如何入手! 跪求java的视频聊天网站实现方式或原码 初学者问题``请大家帮下`不然我没有学下去
先把配置数据序列化到一个文件里,上传该文件即可。
as:
import cz.dhl.ftp.Ftp;
import cz.dhl.ftp.FtpConnect;
import cz.dhl.ftp.FtpFile;
import cz.dhl.io.CoFile;
import cz.dhl.io.CoLoad;
import cz.dhl.io.LocalFile;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;import java.io.File;
import java.io.IOException;public class FileServer { private static final Log LOG = LogFactory.getLog(FileServer.class); private static FileServer instance; public static FileServer getInstance() {
if (instance == null) {
instance = new FileServer();
} return instance;
} // 文件服务器的绝对路径
private String fileServerDir; private FileServer() {
} /**
* 获取文件服务器的绝对路径
*/
public String getFileServerDir() {
return fileServerDir;
} public static String getFullPath(String parent, String fileName) {
File file = new File(parent, fileName);
return file.getAbsolutePath();
} public static void list(String host, String username, String passwd) {
// host = ftp.datangmobile.com;
// path = pub;
// user = anonymous (default);
// port = 21 (default); */
FtpConnect cn = FtpConnect.newConnect(host);
cn.setHostName(host);
cn.setPathName("c:\\");
// Guest login ok, send your password
cn.setUserName(username);
cn.setPassWord(passwd);
Ftp cl = new Ftp(); try {
// connect & login to host
if(!cl.connect(cn)){
LOG.info("连接FTP服务器失败,三秒后再次尝试连接!");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
LOG.error("FTP三秒尝试中断过程中出现异常!", e);
}
LOG.info("再次尝试连接到FTP服务器.");
cl.connect(cn);
}
// get current directory
CoFile dir = new FtpFile(cl.pwd(), cl); // list & print current directory
CoFile fls[] = dir.listCoFiles();
if (fls != null) {
for (CoFile fl : fls) {
System.out.println(fl.getName()
+ (fl.isDirectory() ? "/" : ""));
}
}
} catch (IOException e) {
LOG.error("FTP ERROR!", e);
} finally {
// disconnect from server this must be always run
cl.disconnect();
}
} public static boolean upload(String host, String username, String passwd,
String path, String name, String remoteName) {
// host = ftp.datangmobile.com;
// path = pub;
// user = anonymous (default);
// port = 21 (default); */
FtpConnect cn = FtpConnect.newConnect(host);
cn.setHostName(host);
//cn.setPathName("abc");
cn.setUserName(username);
cn.setPassWord(passwd);
Ftp cl = new Ftp();
int connectNum=0;
try {
// connect & login to host
while(!cl.connect(cn)){
LOG.info("连接FTP服务器失败,三十秒后再次尝试连接!");
if(connectNum++>=5){
LOG.info("累计尝试连接FTP已达五次,连接失败.");
return false;
}
try {
Thread.sleep(30000);
} catch (InterruptedException e) {
LOG.error("FTP三十秒尝试中断过程中出现异常!", e);
}
LOG.info("再次尝试连接到FTP服务器.......");
}
// source FtpFile remote file
CoFile file = new FtpFile(remoteName, cl);
// destination LocalFile
CoFile to = new LocalFile(path, name); // 上传
CoLoad.copy(file, to); // 上载
//CoLoad.copy(to,file);
} catch (IOException e) {
LOG.error("FTP ERROR!", e);
} finally {
cl.disconnect();
}
return true;
} public static void download(String host, String username, String passwd,
String path, String name, String remoteName) {
// host = ftp.datangmobile.com;
// path = pub;
// user = anonymous (default);
// port = 21 (default); */
FtpConnect cn = FtpConnect.newConnect(host);
cn.setHostName(host);
//cn.setPathName("abc");
cn.setUserName(username);
cn.setPassWord(passwd); Ftp cl = new Ftp();
try {
// connect & login to host
cl.connect(cn); // source FtpFile remote file
CoFile file = new FtpFile(remoteName, cl); // destination LocalFile
CoFile to = new LocalFile(path, name); // 下载
CoLoad.copy(to,file);
} catch (IOException e) {
LOG.error("FTP ERROR!", e);
} finally {
cl.disconnect();
}
}
public static void delete(String host, String username, String passwd,
String path, String name, String remoteName) {
// host = ftp.datangmobile.com;
// path = pub;
// user = anonymous (default);
// port = 21 (default); */
FtpConnect cn = FtpConnect.newConnect(host);
cn.setHostName(host);
//cn.setPathName("abc");
cn.setUserName(username);
cn.setPassWord(passwd); Ftp cl = new Ftp();
try {
// connect & login to host
cl.connect(cn); // source FtpFile remote file
CoFile[] file = new FtpFile[]{new FtpFile(remoteName, cl)};
//删除
CoLoad.delete(file); } catch (IOException e) {
LOG.error("FTP ERROR!", e);
} finally {
cl.disconnect();
}
}
}