如何java判断ftp服务器上路径是否存在
要注意的是程序有可能和FTP不再同一台服务器上,所以要多做一些工作,先要根据获取FTP的IP,根据这个IP的FTP目录 在进行判断
代码如下
=======接口部分===============
IMPORT JAVA.RMI.REMOTE;
IMPORT JAVA.RMI.REMOTEEXCEPTION;
PUBLIC INTERFACE IDOREMOTE EXTENDS REMOTE {
PUBLIC INT GETSERVERTIME() THROWS REMOTEEXCEPTION;
}
=======接口实现===============
PUBLIC CLASS DOREMOTEIMPL EXTENDS UNICASTREMOTEOBJECT IMPLEMENTS IDOREMOTE {
/**
* @THROWS REMOTEEXCEPTION
*/
PROTECTED DOREMOTEIMPL() THROWS REMOTEEXCEPTION {
SUPER();
}
PRIVATE STATIC FINAL LONG SERIALVERSIONUID = -8158779541912069375L;
/**
* @SEE CN.SHIY.TEST.REMOTESERVER.IDOREMOTE#GETSERVERTIME()
*/
PUBLIC INT GETSERVERTIME() THROWS REMOTEEXCEPTION {
RETURN INTEGER.PARSEINT(NEW SIMPLEDATEFORMAT("YYYYMMDD").FORMAT(NEW DATE()));
// RETURN NEW DATE();
}
========SERVER端绑定===============
PUBLIC STATIC VOID MAIN(STRING[] ARGS) {
TRY {
LOCATEREGISTRY.CREATEREGISTRY(8808);
DOREMOTEIMPL SERVER = NEW DOREMOTEIMPL();
NAMING.REBIND("//LOCALHOST:8808/DATE-SERVER", SERVER);
} CATCH (JAVA.NET.MALFORMEDURLEXCEPTION ME) {
SYSTEM.OUT.PRINTLN("MALFORMED URL: " + ME.TOSTRING());
} CATCH (REMOTEEXCEPTION RE) {
SYSTEM.OUT.PRINTLN("REMOTE EXCEPTION: " + RE.TOSTRING());
}
}
===========客户端的调用方式============
STRING URL = "//LOCALHOST:8808/DATE-SERVER";
IDOREMOTE RMIOBJECT = (IDOREMOTE) NAMING.LOOKUP(URL);
SYSTEM.OUT.PRINTLN(" SERVER DATE: " + RMIOBJECT.GETSERVERTIME());