1

I need to program an FTP upload. So far no problem BUT I have to use a proxy to do so. Sadly its not a FTP proxy but a HTTP proxy so I get the typical error that uploading is not available with HTTP proxies. To correct this I tried the typical workaround with ftp.Proxy set to null (nothing in VB). But then I get the error message that the host cannot be found.

So I'm wondering what I'm doing wrong there? OR am I in a situation there where it is impossible to use FtpWebRequest?

FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create("ftp://ftp.targetserver.com/automaticUpload/test.txt");
ftp.Credentials = new NetworkCredential("myuser", "passwd");
ftp.UseBinary = true;
//ftp.Proxy = new WebProxy("proxy1");
ftp.Proxy = null;
ftp.Method = WebRequestMethods.Ftp.UploadFile;

FileStream fs = File.OpenRead(@"C:\blah\blubb\blah\t1.txt.txt");
byte [] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
fs.Close();

Stream ftpStream = ftp.GetRequestStream();
ftpStream.Write(buffer, 0, buffer.Length);

Edit: As it seems the information I got there that there is a working workaround was wrong. Thus the other questions answers are fully correct (still) that there is no way to do this with plain c#.

Thomas
  • 2,886
  • 3
  • 34
  • 78
  • @MartinPrikryl I took a look at that question and others that were done afterwards. There IS a workaround (setting ftp.Proxy = null) which seemingly works in the other similar questions but not for me. That is why I made this question as I found it strange that for 3 questions made in regards to this proxy = null works but for me not. – Thomas Oct 06 '15 at 10:43
  • Can you points us to a post claiming that `proxy = null` works? – Martin Prikryl Oct 06 '15 at 10:45
  • @MartinPrikryl Sure: http://stackoverflow.com/questions/19498143/ftp-upload-file-the-requested-ftp-command-is-not-supported-when-using-http-proxy One of the answers there. And a codeproject post also: http://www.codeproject.com/Questions/332730/FTP-proxy-problem-in-Csharp-application In the worst case I just misunderstood what they meant there then? – Thomas Oct 06 '15 at 10:53
  • Did I misunderstand what they did in the posts mentioned by me there and there is no real way (as in the question mentioned as possible duplicate?) – Thomas Oct 06 '15 at 10:56
  • These posts are just non-sense, imho. – Martin Prikryl Oct 06 '15 at 11:02
  • You simply have to use another FTP library. – Martin Prikryl Oct 06 '15 at 11:03
  • @MartinPrikryl tnx. If nothing else comes up within the next 1-2 hours I will edit it into the question itself and see it answered by the other question (with the possible workarounds being nonsense) – Thomas Oct 06 '15 at 11:10

0 Answers0