我想上传一个 pdf 文件到 ftp 服务器。我已经这样做了,但它显示一个错误:
System.Net.WebException:请求的 URI 对于此 FTP 命令无效。
protected void UploadButton_Click(object sender, EventArgs e)
{
System.Net.FtpWebRequest rq = (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create("ftp://www.xxxx.co/yyyy/");
rq.Credentials = new System.Net.NetworkCredential("xxxx", "*****");
rq.Method = System.Net.WebRequestMethods.Ftp.UploadFile;
System.IO.Stream fs = FileUploadControl.PostedFile.InputStream;
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
fs.Close();
System.IO.Stream ftpstream = rq.GetRequestStream();
ftpstream.Write(buffer, 0, buffer.Length);
ftpstream.Close();
}
请帮忙。我怎样才能上传一个pdf文件?