Ftp throws WebException only in .NET 4.0
Posted
by
Trakhan
on Stack Overflow
See other posts from Stack Overflow
or by Trakhan
Published on 2011-01-05T13:44:24Z
Indexed on
2011/01/05
13:54 UTC
Read the original article
Hit count: 208
I have following c# code. It runs just fine when compiled against .NET framework 3.5 or 2.0 (I did not test it against 3.0, but it will most likely work too). The problem is, that it fails when built against .NET framework 4.0.
FtpWebRequest Ftp = (FtpWebRequest)FtpWebRequest.Create(Url_ + '/' + e.Name);
Ftp.Method = WebRequestMethods.Ftp.UploadFile;
Ftp.Credentials = new NetworkCredential(Login_, Password_);
Ftp.UseBinary = true;
Ftp.KeepAlive = false;
Ftp.UsePassive = true;
Stream S = Ftp.GetRequestStream();
byte[] Content = null;
bool Continue = false;
do
{
try
{
Continue = false;
Content = File.ReadAllBytes(e.FullPath);
}
catch (Exception)
{
Continue = true;
System.Threading.Thread.Sleep(500);
}
} while (Continue);
S.Write(Content, 0, Content.Length);
S.Close();
FtpWebResponse Resp = (FtpWebResponse)Ftp.GetResponse();
if (Resp.StatusCode != FtpStatusCode.CommandOK)
Console.WriteLine(Resp.StatusDescription);
The problem is in call Stream S = Ftp.GetRequestStream();, which throws an en instance of WebException with message “The remote server returned an error: (500) Syntax error, command unrecognized”.
Does anybody know why it is so?
PS. I communicate virtual ftp server in ECM Alfresco.
© Stack Overflow or respective owner