As I understand it, the FtpWebRequest.Proxy
property denotes an HTTP proxy. I have to issue FTP requests to an external server via an FTP proxy.
The only way I've got this to work so far is by creating a script which uses the Windows FTP command and downloading that way.
Is it possible to use the FtpWebRequest
to download files via an FTP proxy?
If you have the budget for it - Dart do some great classes for this:
http://www.dart.com/ or specifically http://www.dart.com/ptftpnet.aspx
Here's code I've used before, I should caveat I've only tested this against a Checkpoint firewall so the format USER and PASS commands maybe different for your FTP Proxy. Your system administrator will know the correct format.
I know this is way past the due date, but yes, I'm able to get FtpWebRequest to work with an ftp proxy by using the old tricks of setting the URL to
Then set your network credential to
and
I remembered doing this back in the bad old WININET days, and sometimes the old tricks are still the best tricks.
YMMV of course.
They claim it is possible to list, listdetails, and download through a proxy. However I could not get this to work with an isa firewall. So I disabled the default proxy in my app.config and added an application rule for ForeFront/ISA client. To do this I created a file c:\programdata\microsoft\firewall client 2004\application.ini with the contents:
[applicationName] DisableEx=0 Disable=0 NameResolution=R
where applicationName is the running exe minus the .exe extension.
If the FTP proxy allows specifying all information about the target via
USER
andPASS
commands, you can use theCredentials
property.Typically, you specify the username in a form
user@proxyuser@host
and password in a formpassword@proxypassword
:If the proxy does not require authentication, use a form
user@host
andpassword
:But your proxy server may also require a different syntax, like:
USER
commands for proxy user and target host userOPEN
commandSITE
commandIn these cases, you cannot use the
FtpWebRequest
. You must use a 3rd party FTP client library instead.For example with WinSCP .NET assembly, you can use:
For the options for the
SessionOptions.AddRawSettings
, see raw settings.Easier is to configure the proxy settings in WinSCP GUI and have it generate C# FTP code template for you.
Note that WinSCP .NET assembly is not a native .NET library. It's rather a thin .NET wrapper over a console application.
(I'm the author of WinSCP)