【问题标题】:Apache FTPClient: Read welcome messageApache FTPClient:阅读欢迎信息
【发布时间】:2016-03-11 11:04:36
【问题描述】:

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

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

【问题讨论】:

  • @MartinPrikryl 当然是关于编程的,我想知道,是否有办法在我的 Java 程序中从服务器检索欢迎消息?
  • @MartinPrikryl 对不起,问错了!将编辑我的帖子。

标签: java ftp apache-commons-net


【解决方案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();

【讨论】:

  • 谢谢你,它工作得很好!我很抱歉造成混乱!
猜你喜欢
  • 2021-09-23
  • 1970-01-01
  • 1970-01-01
  • 2023-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-11
相关资源
最近更新 更多