Possible Duplicate:
How do you change directories using FtpWebRequest (.NET)?
private void InitFTPTransfer(string filePath)
{
string[] ftpAddress = ddcdao.ddcAddress.Split(new string[] { "http://" }, StringSplitOptions.None);
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://" + ftpAddress[1] + "/root/" + Path.GetFileName(filePath));
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential(Properties.Settings.Default.SysFTPID, Properties.Settings.Default.SysFTPPassword);
byte[] fileContents = File.ReadAllBytes(filePath);
request.ContentLength = fileContents.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
response.Close();
}
I have the above code to upload a particular file to a path.
Inside the ftp, how do I set a particular directory to upload the file on?
In this case, I’m uploading to a machine with embedded linux so it needs to be under /root/somedirectory
Edit: I’ve tried the suggestions of actually including the directory path in the request path but it just throws a System.Net.WebException with the message “System error” on the line of request.GetRequestStream();
You put the directory in the request’s path, i.e.