Actualy our Proxy is capable of executing FTP requests on the clients
behalf. 

I tested this using firefox (Where I have configured our proxy server)
I run the following URI: ftp://username:[EMAIL PROTECTED]/testdir/

I use a sniffer to look at the GET commond send to the proxy server. It
looks as follows:

GET ftp://username:[EMAIL PROTECTED]/testdir/ HTTP/1.1
Host: ftp.mytest.test
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12)
Gecko/20050915 Firefox/1.0.7
Accept:
text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=
0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Proxy-Connection: keep-alive

Using this request we get access to the directory and see the contents
displayed.
However, when I try the same in Java I get the following GET request (Java
code included below):

GET ftp://ftp.mytest.test/testdir/ HTTP/1.1
User-Agent: Jakarta Commons-HttpClient/3.0-rc3
Host: ftp.mytest.test
Proxy-Connection: Keep-Alive

Finally I get a ACCESS DENIED error. 
This seems to be because the GET request does not contain the USER /
PASSWORD info in the URL.

Any Ideas?


/// JAVA CODE:

package nl.essent.test.ftp.httptest;

import java.io.IOException;

import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.NTCredentials;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory;
import org.apache.commons.httpclient.protocol.Protocol;

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("xxxx", "xxxxx","",
"xxxx" );
        client.getState().setProxyCredentials(AuthScope.ANY, proxyCreds);
        
        GetMethod gmethod = new
GetMethod("ftp://username:[EMAIL PROTECTED]/testdir/");
        
        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();
          } 

    }

}

//// END JAVA CODE

Many thanks,

Regards,

Harm de Laat


-----Original Message-----
From: Oleg Kalnichevski [mailto:[EMAIL PROTECTED]
Sent: 20 December 2005 15:25
To: [email protected]
Subject: Re: ftp via http


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" <[EMAIL PROTECTED]> 
> 20.12.2005 13:51
> Please respond to
> "HttpClient User Discussion"
> 
> 
> To
> "'[email protected]'" 
> <[email protected]>
> 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:[EMAIL PROTECTED]/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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to