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#.