Apache FTPClient:阅读欢迎消息



使用我的Java程序,我正在使用Apache Commons Net连接到FTP服务器。FTP 服务器用作我的软件的更新服务器,目前每次我检查更新时,更新程序都会下载一个.txt并检查文件中写入的版本号是否大于计算机上当前安装的版本号。

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

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

因此,使用 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();

最新更新