Is there a way to upload a file to a FTP server when behind an HTTP proxy ?
It seems that uploading a file is not supported behind an HTTP Proxy using .Net Webclient. (http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.proxy.aspx).
If there is no workaround ? If not, do you know a good and free FTP library I can use ?
Edit: Unfortunately, I don't have any FTP proxy to connect to.
I've just had the same problem.
My primary goal was to upload a file to an ftp. And I didn't care if my traffic would go through proxy or not.
So I've just set FTPWebRequest.Proxy property to null right after FTPWebRequest.Create(uri).
And it worked. Yes, I know this solution is not the greatest one. And more of that, I don't get why did it work. But the goal is complete, anyway.
As Alexander says, HTTP proxies can proxy arbitrary traffic. What you need is an FTP Client that has support for using a HTTP Proxy. Alexander is also correct that this would only work in passive mode.
My employer sells such an FTP client, but it is a enterprise level tool that only comes as part of a very large system.
I'm certain that there are others available that would better fit your needs.
I'm not sure if all HTTP proxies work in the same way, but I managed to cheat ours by simply creating an HTTP request to access resource on URI ftp://user:pass@your.server.com/path.
Sadly, to create an instance of HttpWebRequest you should use WebRequest.Create. And if you do that you can't create an HTTP request for ftp:// schema.
So I used a bit of reflection to invoke a non-public constructor which does that:
You can also use other methods like "DELETE" for other tasks.
In my case, it worked like a charm.
One solution is to try Mono's implementation of FtpWebRequest. I had a look at its source code and it appears it'll be easy to modify so that all connections (control and data) are tunneled via an HTTP proxy.
You establish a TCP connection to your HTTP proxy instead of the actual FTP server. Then you send
CONNECT myserver:21 HTTP/1.0
followed by two CRLFs (CRLF = \r\n). If the proxy needs authentication, you need to use HTTP/1.1 and also send a proxy authentication header with the credentials. Then you need to read the first line of the response. If it starts with "HTTP/1.0 200
" or "HTTP/1.1 200
", then you (the rest of the code) can continue using the connection as though it's connected directly to the FTP server.Damn these unfree applications and components!!! Here is my open source C# code that can uploads file to FTP via HTTP proxy.
If there's a way for you to upload a file via FTP without C# then it should also be possible in C#. Does uploading via browser or an FTP client work?
The one FTP library I like the most is .NET FTP Client library.