hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Laat, Harm de" <Harm.deL...@essent.nl>
Subject ftp via http
Date Tue, 20 Dec 2005 12:51:01 GMT
Hi all, 

I'm trying to access a FTP server via a HTTP proxy server (in this case
Microsoft ISA server).

I have to authenticate with my FTP server. So I tried to incorporate my
username and password in the ftp url:

ftp://test:test@xxx.xxx.xxx.xxx/test

However, no luck just yet... I have also tried to set the username and
password with the setCredentials method. Also without luck.

Can somebody please help???



I have written the following code:


// imports //

public class TestClient {

    public static void main(String[] args) {
        new TestClient().testFtpViaHttp();
    }
    
    public void testFtpViaHttp() {
        
        HttpClient client = new HttpClient();
        
        HostConfiguration hostConfig = client.getHostConfiguration();
        hostConfig.setProxy("proxy", 8080);
        client.setHostConfiguration(hostConfig);
        
        Protocol protol = new Protocol("ftp", new
DefaultProtocolSocketFactory(), 21);
        Protocol.registerProtocol("ftp", protol);
        
        Credentials proxyCreds = new NTCredentials("username", "pass","",
"DOMAIN" );
        client.getState().setProxyCredentials(AuthScope.ANY, proxyCreds);
        
        GetMethod gmethod = new GetMethod("ftp://xxx.xxx.xxx.xxx/test/");
                
        gmethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, 
                new DefaultHttpMethodRetryHandler(3, false));
       
        try {
            // Execute the method.
            int statusCode = client.executeMethod(gmethod);

            if (statusCode != HttpStatus.SC_OK) {
              System.err.println("Method failed: " +
gmethod.getStatusLine());
            }

            // Read the response body.
            byte[] responseBody = gmethod.getResponseBody();

            // Deal with the response.
            // Use caution: ensure correct character encoding and is not
binary data
            System.out.println(new String(responseBody));

          } catch (HttpException e) {
            System.err.println("Fatal protocol violation: " +
e.getMessage());
            e.printStackTrace();
          } catch (IOException e) {
            System.err.println("Fatal transport error: " + e.getMessage());
            e.printStackTrace();
          } finally {
            // Release the connection.
            gmethod.releaseConnection();
          } 

    }

}


Regards,

Harm de Laat


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message