我正在尝试在 ftp Web 服务器上上传文件。我在 windows phone 中找不到FtpWebRequest类,所以我尝试通过添加可移植类库的新项目来尝试它。我添加了以下代码
public void GetDataUsingDataContract(byte[] fileByte)
{
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.contoso.com/test.htm");
request.Method = WebRequestMethods.Ftp.UploadFile;
// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential("uname", "pass");
// Copy the contents of the file to the request stream.
// StreamReader sourceStream = new StreamReader("testfile.txt");
byte[] fileContents = fileByte;//Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
//sourceStream.Close();
request.ContentLength = fileContents.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);
response.Close();
}
但也有同样的问题,即我找不到FtpWebResponse类。可移植类库是否支持它?