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 with virtual ftp server in ECM Alfresco.
edit: I recently found out, that it is not possible to have .NET framework 3.5 windows service on Windows 7, so it would be nice to solve this issue. The thing I need to do is upload file to ftp - is there another (working) way in c#?
edit2: previous edit is not true, I got somewhat confused ...