I’m working on a program where I am uploading multiple files to an FTP. I need to complete 8 actions in doing this:
- Create a new folder within the FTP
- Upload three files to the new directory
- Create three subdirectories within the new directory
From what I’ve gathered, I’m only able to process one method in FtpWebRequest, much like this:
FtpWebrequest request = WebRequest.Create("ftp://microsoft.com/NewDir/") as FtpWebRequest;
request.Method = WebRequestMethods.Ftp.MakeDirectory;
request.Credentials = new NetworkCredentials("username", "password");
FtpWebResponse response = request.GetResponse() as FtpWebResponse;
response.Close();
So am I going to have to write code to also create the subdirectories and stream the files upload separately? Or is it possible to complete all of this within the single connection?
This is my first post, so if formatting is messed up I apologize.
You don’t have to close the connection. Just process your request, get the response from the server like you have [
request.GetResponse()], and move on the next method. When you are done with everything, close the connection.The list of methods you can set is located in the enumeration
WebRequestMethods.Ftp. Please see them at this link.