简体   繁体   中英

Apache FTPClient: Read welcome message

With my Java-Program I'm connecting to a FTP server with Apache Commons Net. The FTP server works as the update server for my software and currently everytime I check for updates, the updater downloads a .txt and checks if the version number written in the file is greater than the version number currently installed on the machine.

Is there a way to get the version number of the update for the software on the machine from the welcome-message of the FTP server? Then I don't have to download the .txt to check for updates instead I'm able to only connect to the server and check the welcome-message for the number?

The welcome message is effectively a "response" to a connection.

So after you connect using the FTPClient.connect() , use the FTPClient.getReplyStrings() to retrieve the welcome message.

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM