Link to home
Start Free TrialLog in
Avatar of andre72
andre72

asked on

FTP Client with FtpWebRequest

Hi,

I have a small command tool we use to get some data from a FTP server.
The matter is that the network is now after a proxy server and to connect to the FTP server the proxy mode is USER@HOST.
I found some samples to connect with this using a socket but no sample how to connect to using FtpWebRequest.
As I don't change the whole class I would prefer this way to connect ...

Is there a way how to do?

Thanks

Andre
//create request
FtpWebRequest result = (FtpWebRequest)FtpWebRequest.Create(URI);
//Set the login details
result.Credentials = Credentials;//GetCredentials();
//Do not keep alive (stateless mode)
result.KeepAlive = true;

// Set Proxy if need for
IWebProxy wp=null;
if (!String.IsNullOrEmpty(Proxy))
{
    if (String.IsNullOrEmpty(Port))
        wp = new WebProxy(Proxy);
    else
        wp = new WebProxy(Proxy,int.Parse(Port));

    if (!String.IsNullOrEmpty(ProxyUsername))
        wp.Credentials = ProxyCredentials;
}
result.Proxy = wp;
result.UsePassive = true;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of nmarun
nmarun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of andre72
andre72

ASKER

Thanks, this is very simular to my function and this worked fine before there was a proxy installed.
Now I can access using FF like ftp://user:pw@domain/file but what ever I try now from my client it can't connect.
Is there a way to trace FTP like fiddler for HTTP?
i have a query, r u upload something in server?
Avatar of andre72

ASKER

No uploads, just DL.

I figured out that WebClient request = new WebClient(); seems to work with the proxy settings so it works fine now. Thanks