我在.NEt 2.0中使用c#来简单地尝试上传文件.代码中的一切似乎都没问题,但是当我从FtpWebRequest.GetRequestStream方法创建流时它仍然失败.
这是代码......
FtpWebRequest ftpRequest;
FtpWebResponse ftpResponse;
try
{
string fileName = Path.GetFileName(strCompleteFilePath);
ftpRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://myhost/" + fileName));
ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
ftpRequest.Proxy = null;
ftpRequest.UseBinary = true;
ftpRequest.Credentials = new NetworkCredential("myUserID", "myPW");
ftpRequest.KeepAlive = false;
FileInfo ff = new FileInfo(strCompleteFilePath);
byte[] fileContents = new byte[ff.Length];
using (FileStream fr = ff.OpenRead())
{
fr.Read(fileContents, 0, Convert.ToInt32(ff.Length));
}
using (Stream writer = ftpRequest.GetRequestStream())
{
writer.Write(fileContents, 0, fileContents.Length);
}
ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
}
Run Code Online (Sandbox Code Playgroud)
而错误....
{System.Net.WebException: The remote server returned an error: (501) Syntax …Run Code Online (Sandbox Code Playgroud)