You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by "Laat, Harm de" <Ha...@essent.nl> on 2005/12/20 13:51:01 UTC

ftp via http

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


Re: ftp via http

Posted by Roland Weber <RO...@de.ibm.com>.
Hi Oleg,

> Actually some web proxies are capable of executing FTP requests on the 
> client's behalf. So, this is a legitimate usage of HttpClient

So the HTTP request with an ftp: URL is translated by the proxy
to an FTP transaction, and the result is returned via HTTP?
Interesting. Thanks for telling me, I wasn't aware of that.

cheers,
  Roland



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: ftp via http

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, Dec 20, 2005 at 03:14:39PM +0100, Roland Weber wrote:
> Hello Harm,
> 
> FTP and HTTP are completely different protocols.
> You can not use HttpClient to access an FTP server.
> 
> You may be able to tunnel FTP via an HTTP proxy,
> but HttpClient will only help you with the tunnelling.
> You still have to implement FTP yourself, including
> the authentication against the FTP server.
> 
> cheers,
>   Roland
> 

Roland,

Actually some web proxies are capable of executing FTP requests on the 
client's behalf. So, this is a legitimate usage of HttpClient

Harm,

Please send a wire/context log of the HTTP session that exhibits the
problem

Oleg

> 
> 
> 
> "Laat, Harm de" <Ha...@essent.nl> 
> 20.12.2005 13:51
> Please respond to
> "HttpClient User Discussion"
> 
> 
> To
> "'httpclient-user@jakarta.apache.org'" 
> <ht...@jakarta.apache.org>
> cc
> 
> Subject
> ftp via http
> 
> 
> 
> 
> 
> 
> 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
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: ftp via http

Posted by Roland Weber <RO...@de.ibm.com>.
Hello Harm,

FTP and HTTP are completely different protocols.
You can not use HttpClient to access an FTP server.

You may be able to tunnel FTP via an HTTP proxy,
but HttpClient will only help you with the tunnelling.
You still have to implement FTP yourself, including
the authentication against the FTP server.

cheers,
  Roland




"Laat, Harm de" <Ha...@essent.nl> 
20.12.2005 13:51
Please respond to
"HttpClient User Discussion"


To
"'httpclient-user@jakarta.apache.org'" 
<ht...@jakarta.apache.org>
cc

Subject
ftp via http






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




---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org