我想将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文件?
答案 0 :(得分:1)
System.Net.FtpWebRequest.Create("ftp://xxxx.co/yyyy/");
您的命令会创建一个目录,您需要添加文件名
System.Net.FtpWebRequest.Create("ftp://xxxx.co/yyyy/file.pdf");