2016-03-11 52 views
1

使用我的Java程序,我使用Apache Commons Net连接到FTP服务器。 FTP服务器作为我软件的更新服务器,当前每次检查更新时,更新程序都下载一个.txt文件,并检查写入文件的版本号是否大于当前安装在机器上的版本号。Apache FTPClient:读取欢迎消息

有没有办法从FTP服务器的欢迎信息中获取机器上软件的更新版本号? 然后,我不必下载.txt来检查更新,而只能连接到服务器并检查号码的欢迎信息?

+0

@MartinPrikryl当然是关于编程,我想知道,如果有一种方法来从我的Javaprogramm中的服务器检索welcomemessage? –

+0

@MartinPrikryl对不起,问错了!将编辑我的帖子。 –

回答

1

欢迎消息实际上是对连接的“响应”。

因此,使用FTPClient.connect()进行连接后,请使用FTPClient.getReplyStrings()来检索欢迎消息。

ftp.connect(server); 

// After connection attempt, you should check the reply code to verify success. 
reply = ftp.getReplyCode(); 

if (!FTPReply.isPositiveCompletion(reply)) 
{ 
    ftp.disconnect(); 
    System.err.println("FTP server refused connection."); 
    System.exit(1); 
} 

// read the initial response (aka "Welcome message") 
String[] welcomeMessage = ftp.getReplyStrings(); 
+1

谢谢,它完美的作品!我对这种混乱感到抱歉! –