Reputation: 349
I want to upload a pdf file to ftp server. I have done it this way but it shows an error:
System.Net.WebException: The requested URI is invalid for this FTP command.
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();
}
please help. how can I upload a pdf file ?
Upvotes: 2
Views: 2778
Reputation: 45490
System.Net.FtpWebRequest.Create("ftp://xxxx.co/yyyy/");
Your command creates a directory instead, you need to add the file name
System.Net.FtpWebRequest.Create("ftp://xxxx.co/yyyy/file.pdf");
Upvotes: 1