ftp request through ftp proxy : CSharp
This is a discussion on ftp request through ftp proxy within the CSharp forums in Programming Languages category; Hi, I have to upload files on a ftp server through a ftp proxy with Dotnet. I have a 'System.InvalidOperationException' with this message : "The requested FTP command is not supported when using HTTP proxy". Is there a solution to use a FTP proxy and not a HTTP proxy ? Thanks Marc My code (in CLI/C++, but the same in C#) : // Get the object used to communicate with the server. FtpWebRequest^ request = (FtpWebRequest^)WebRequest::Create("ftp:// xxx.xxx.com"); // Uri of ftp server request->Method = WebRequestMethods::Ftp::UploadFile; // FTP Proxy request->Proxy = gcnew WebProxy("ftpProxyHostname", 21); request->Credentials = gcnew NetworkCredential("ftpServerUser","password"); // Copy the ...
![]() |
| | LinkBack | Thread Tools |
|
#1
| |||
| |||
| I have to upload files on a ftp server through a ftp proxy with Dotnet. I have a 'System.InvalidOperationException' with this message : "The requested FTP command is not supported when using HTTP proxy". Is there a solution to use a FTP proxy and not a HTTP proxy ? Thanks Marc My code (in CLI/C++, but the same in C#) : // Get the object used to communicate with the server. FtpWebRequest^ request = (FtpWebRequest^)WebRequest::Create("ftp:// xxx.xxx.com"); // Uri of ftp server request->Method = WebRequestMethods::Ftp::UploadFile; // FTP Proxy request->Proxy = gcnew WebProxy("ftpProxyHostname", 21); request->Credentials = gcnew NetworkCredential("ftpServerUser","password"); // Copy the contents of the file to the request stream. StreamReader^ sourceStream = gcnew StreamReader(exportDirectory + zipName); array<Byte>^ fileContents = Encoding::UTF8->GetBytes(sourceStream- >ReadToEnd()); sourceStream->Close(); request->ContentLength = fileContents->Length; Stream^ requestStream = request->GetRequestStream(); requestStream->Write(fileContents, 0, fileContents->Length); requestStream->Close(); FtpWebResponse^ response = (FtpWebResponse^)request->GetResponse(); |
|
#2
| |||
| |||
| But lol what ! |
|
#3
| |||
| |||
| The documentation for the Proxy property on the FtpWebRequest class states: The FtpWebRequest class supports HTTP and ISA Firewall Client proxies. This leads me to believe that these are the only proxies it supports. Also, when using an HTTP proxy, you are limited to the methods that you can use: If the specified proxy is an HTTP proxy, only the DownloadFile, ListDirectory, and ListDirectoryDetails commands are supported. I don't know if it supports an FTP proxy, but you might try and create a URI with the FTP scheme, address, and port, and pass that to your WebProxy instance and see if that works. -- - Nicholas Paldino [.NET/C# MVP] - mvp@spam.guard.caspershouse.com "squall" <squall2022@gmail.com> wrote in message news:5f19839f-926b-4733-ab0c-58fd43539eb9@u10g2000prn.googlegroups.com... > Hi, > I have to upload files on a ftp server through a ftp proxy with > Dotnet. > I have a 'System.InvalidOperationException' with this message : "The > requested FTP command is not supported when using HTTP proxy". Is > there a solution to use a FTP proxy and not a HTTP proxy ? > > Thanks > Marc > > My code (in CLI/C++, but the same in C#) : > > // Get the object used to communicate with the server. > FtpWebRequest^ request = (FtpWebRequest^)WebRequest::Create("ftp:// > xxx.xxx.com"); // Uri of ftp server > request->Method = WebRequestMethods::Ftp::UploadFile; > > // FTP Proxy > request->Proxy = gcnew WebProxy("ftpProxyHostname", 21); > > request->Credentials = gcnew > NetworkCredential("ftpServerUser","password"); > > // Copy the contents of the file to the request stream. > StreamReader^ sourceStream = gcnew StreamReader(exportDirectory + > zipName); > array<Byte>^ fileContents = Encoding::UTF8->GetBytes(sourceStream- >>ReadToEnd()); > sourceStream->Close(); > request->ContentLength = fileContents->Length; > > Stream^ requestStream = request->GetRequestStream(); > requestStream->Write(fileContents, 0, fileContents->Length); > requestStream->Close(); > > FtpWebResponse^ response = (FtpWebResponse^)request->GetResponse(); |
|
#4
| |||
| |||
| Thanks for your response. I tried your solution, but it doesn't work, I have this message : 'System.NotSupportedException', "ftp scheme proxies are not supported by ServicePointManager". (I hope this is a good traduction, I'm french and my Visual Studio is in French )Do you know another class instead of FtpWebRequest, allowing me to do a ftp request through a ftp proxy ? On 23 jan, 17:16, "Nicholas Paldino [.NET/C# MVP]" <m...@spam.guard.caspershouse.com> wrote: > The documentation for the Proxy property on the FtpWebRequest class > states: > > The FtpWebRequest class supports HTTP and ISA Firewall Client proxies. > > This leads me to believe that these are the only proxies it supports. > > Also, when using an HTTP proxy, you are limited to the methods that you > can use: > > If the specified proxy is an HTTP proxy, only the DownloadFile, > ListDirectory, and ListDirectoryDetails commands are supported. > > I don't know if it supports an FTP proxy, but you might try and create a > URI with the FTP scheme, address, and port, and pass that to your WebProxy > instance and see if that works. > > -- > - Nicholas Paldino [.NET/C# MVP] > - m...@spam.guard.caspershouse.com > > "squall" <squall2...@gmail.com> wrote in message > > news:5f19839f-926b-4733-ab0c-58fd43539eb9@u10g2000prn.googlegroups.com... > > > Hi, > > I have to upload files on a ftp server through a ftp proxy with > > Dotnet. > > I have a 'System.InvalidOperationException' with this message : "The > > requested FTP command is not supported when using HTTP proxy". Is > > there a solution to use a FTP proxy and not a HTTP proxy ? > > > Thanks > > Marc > > > My code (in CLI/C++, but the same in C#) : > > > // Get the object used to communicate with the server. > > FtpWebRequest^ request = (FtpWebRequest^)WebRequest::Create("ftp:// > > xxx.xxx.com"); // Uri of ftp server > > request->Method = WebRequestMethods::Ftp::UploadFile; > > > // FTP Proxy > > request->Proxy = gcnew WebProxy("ftpProxyHostname", 21); > > > request->Credentials = gcnew > > NetworkCredential("ftpServerUser","password"); > > > // Copy the contents of the file to the request stream. > > StreamReader^ sourceStream = gcnew StreamReader(exportDirectory + > > zipName); > > array<Byte>^ fileContents = Encoding::UTF8->GetBytes(sourceStream- > >>ReadToEnd()); > > sourceStream->Close(); > > request->ContentLength = fileContents->Length; > > > Stream^ requestStream = request->GetRequestStream(); > > requestStream->Write(fileContents, 0, fileContents->Length); > > requestStream->Close(); > > > FtpWebResponse^ response = (FtpWebResponse^)request->GetResponse(); |
|
#5
| |||
| |||
| squall, I don't know of another class that will let you use an FTP proxy, at least in the framework. You will probably have to look for some third-party provider in order to find something that will allow you to do this. -- - Nicholas Paldino [.NET/C# MVP] - mvp@spam.guard.caspershouse.com "squall" <squall2022@gmail.com> wrote in message news:08d7b5e4-3d54-4626-925a-d83a2da5ca6a@e6g2000prf.googlegroups.com... > Thanks for your response. > I tried your solution, but it doesn't work, I have this message : > 'System.NotSupportedException', "ftp scheme proxies are not supported > by ServicePointManager". (I hope this is a good traduction, I'm french > and my Visual Studio is in French )> Do you know another class instead of FtpWebRequest, allowing me to do > a ftp request through a ftp proxy ? > > On 23 jan, 17:16, "Nicholas Paldino [.NET/C# MVP]" > <m...@spam.guard.caspershouse.com> wrote: >> The documentation for the Proxy property on the FtpWebRequest class >> states: >> >> The FtpWebRequest class supports HTTP and ISA Firewall Client proxies. >> >> This leads me to believe that these are the only proxies it supports. >> >> Also, when using an HTTP proxy, you are limited to the methods that >> you >> can use: >> >> If the specified proxy is an HTTP proxy, only the DownloadFile, >> ListDirectory, and ListDirectoryDetails commands are supported. >> >> I don't know if it supports an FTP proxy, but you might try and >> create a >> URI with the FTP scheme, address, and port, and pass that to your >> WebProxy >> instance and see if that works. >> >> -- >> - Nicholas Paldino [.NET/C# MVP] >> - m...@spam.guard.caspershouse.com >> >> "squall" <squall2...@gmail.com> wrote in message >> >> news:5f19839f-926b-4733-ab0c-58fd43539eb9@u10g2000prn.googlegroups.com... >> >> > Hi, >> > I have to upload files on a ftp server through a ftp proxy with >> > Dotnet. >> > I have a 'System.InvalidOperationException' with this message : "The >> > requested FTP command is not supported when using HTTP proxy". Is >> > there a solution to use a FTP proxy and not a HTTP proxy ? >> >> > Thanks >> > Marc >> >> > My code (in CLI/C++, but the same in C#) : >> >> > // Get the object used to communicate with the server. >> > FtpWebRequest^ request = (FtpWebRequest^)WebRequest::Create("ftp:// >> > xxx.xxx.com"); // Uri of ftp server >> > request->Method = WebRequestMethods::Ftp::UploadFile; >> >> > // FTP Proxy >> > request->Proxy = gcnew WebProxy("ftpProxyHostname", 21); >> >> > request->Credentials = gcnew >> > NetworkCredential("ftpServerUser","password"); >> >> > // Copy the contents of the file to the request stream. >> > StreamReader^ sourceStream = gcnew StreamReader(exportDirectory + >> > zipName); >> > array<Byte>^ fileContents = Encoding::UTF8->GetBytes(sourceStream- >> >>ReadToEnd()); >> > sourceStream->Close(); >> > request->ContentLength = fileContents->Length; >> >> > Stream^ requestStream = request->GetRequestStream(); >> > requestStream->Write(fileContents, 0, fileContents->Length); >> > requestStream->Close(); >> >> > FtpWebResponse^ response = (FtpWebResponse^)request->GetResponse(); > |
|
#6
| |||
| |||
| Hi, Finally I use a batch file (.bat) called in my code. It's not a very good solution, but it work ! Thanks for your help On 23 jan, 18:15, "Nicholas Paldino [.NET/C# MVP]" <m...@spam.guard.caspershouse.com> wrote: > squall, > > I don't know of another class that will let you use an FTP proxy, at > least in the framework. You will probably have to look for some third-party > provider in order to find something that will allow you to do this. > > -- > - Nicholas Paldino [.NET/C# MVP] > - m...@spam.guard.caspershouse.com > > "squall" <squall2...@gmail.com> wrote in message > > news:08d7b5e4-3d54-4626-925a-d83a2da5ca6a@e6g2000prf.googlegroups.com... > > > Thanks for your response. > > I tried your solution, but it doesn't work, I have this message : > > 'System.NotSupportedException', "ftp scheme proxies are not supported > > by ServicePointManager". (I hope this is a good traduction, I'm french > > and my Visual Studio is in French )> > Do you know another class instead of FtpWebRequest, allowing me to do > > a ftp request through a ftp proxy ? > > > On 23 jan, 17:16, "Nicholas Paldino [.NET/C# MVP]" > > <m...@spam.guard.caspershouse.com> wrote: > >> The documentation for the Proxy property on the FtpWebRequest class > >> states: > > >> The FtpWebRequest class supports HTTP and ISA Firewall Client proxies. > > >> This leads me to believe that these are the only proxies it supports. > > >> Also, when using an HTTP proxy, you are limited to the methods that > >> you > >> can use: > > >> If the specified proxy is an HTTP proxy, only the DownloadFile, > >> ListDirectory, and ListDirectoryDetails commands are supported. > > >> I don't know if it supports an FTP proxy, but you might try and > >> create a > >> URI with the FTP scheme, address, and port, and pass that to your > >> WebProxy > >> instance and see if that works. > > >> -- > >> - Nicholas Paldino [.NET/C# MVP] > >> - m...@spam.guard.caspershouse.com > > >> "squall" <squall2...@gmail.com> wrote in message > > >>news:5f19839f-926b-4733-ab0c-58fd43539eb9@u10g2000prn.googlegroups.com... > > >> > Hi, > >> > I have to upload files on a ftp server through a ftp proxy with > >> > Dotnet. > >> > I have a 'System.InvalidOperationException' with this message : "The > >> > requested FTP command is not supported when using HTTP proxy". Is > >> > there a solution to use a FTP proxy and not a HTTP proxy ? > > >> > Thanks > >> > Marc > > >> > My code (in CLI/C++, but the same in C#) : > > >> > // Get the object used to communicate with the server. > >> > FtpWebRequest^ request = (FtpWebRequest^)WebRequest::Create("ftp:// > >> > xxx.xxx.com"); // Uri of ftp server > >> > request->Method = WebRequestMethods::Ftp::UploadFile; > > >> > // FTP Proxy > >> > request->Proxy = gcnew WebProxy("ftpProxyHostname", 21); > > >> > request->Credentials = gcnew > >> > NetworkCredential("ftpServerUser","password"); > > >> > // Copy the contents of the file to the request stream. > >> > StreamReader^ sourceStream = gcnew StreamReader(exportDirectory + > >> > zipName); > >> > array<Byte>^ fileContents = Encoding::UTF8->GetBytes(sourceStream- > >> >>ReadToEnd()); > >> > sourceStream->Close(); > >> > request->ContentLength = fileContents->Length; > > >> > Stream^ requestStream = request->GetRequestStream(); > >> > requestStream->Write(fileContents, 0, fileContents->Length); > >> > requestStream->Close(); > > >> > FtpWebResponse^ response = (FtpWebResponse^)request->GetResponse(); |
|
#7
| |||
| |||
| Hi, I am facing the same problem. Would you please share batch file(.bat) and code for how to use it. Thanks Quote:
|



)