我想将文件上传到QNAP,但是当我调用(FtpWebRequest)WebRequest.Create时出现错误,提示我的uri不正确。
private void UploadToFTP(string localFilePath)
{
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://10.0.0.34:21/")
request.UsePassive = true;
request.Proxy = null;
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential("name", "pwd");
byte[] fileContents;
using (StreamReader sourceStream = new StreamReader(localFilePath))
{
fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
}
request.ContentLength = fileContents.Length;
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(fileContents, 0, fileContents.Length);
}