PHP:在文件列表中查找最新文件(远程文件)

时间:2015-09-15 18:16:23

标签: php

有一个网址 - download.software.com/releases/filename-x.。*。rpm

我们需要准备一份可能的软件URL组合x.0.0.0到x.99.99.99的列表。我们已经下载了版本x.12.4.3。

找到最新的软件版本并检查它是否比当前下载的版本更新,如果它更新则尝试下载。

的问题:

找到最新版本,最快的方法是什么?当我这样做时,需要花费数小时来检查文件是否存在。

public class Sample {
public static void main(String[] args) throws Exception {
     final String userid = "username";
     final String pwd = "password";
     String addressXML="";
     String url="URL";
    //Create an instance of HttpClient.
    final HttpClient client = new HttpClient();
    //com.sun.jersey.api.client.ClientResponse response;
    final URL uri = new URL(url);
    final GetMethod getmethods = new GetMethod(url);
    AuthScope authscope = new AuthScope(uri.getHost(), uri.getPort());
    Credentials defaultcreds = new UsernamePasswordCredentials(userid, pwd);
    client.getState().setCredentials(authscope, defaultcreds);
    getmethods.setDoAuthentication(true);
    client.getParams().setAuthenticationPreemptive(true);
    final int responseCode = client.executeMethod(getmethods);
    if (responseCode == 200) {
        InputStream in = getmethods.getResponseBodyAsStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        StringBuilder out = new StringBuilder();
        String line;
        while ((line = reader.readLine()) != null) {
            out.append(line);
        }
        addressXML = out.toString();
        System.out.println("Resultent Data" + addressXML);   //Prints the string content read from input stream  nodes 
        reader.close();
    } else {
        throw new RuntimeException("Failed : HTTP error code : " + responseCode + " address rs service error!");
    }
}}

提前致谢。

0 个答案:

没有答案