Ask Your Question
3

What is the process of using C# to establish a directory on an FTP server?

asked 2023-07-20 21:41:59 +0000

pufferfish gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-07-20 21:49:02 +0000

huitzilopochtli gravatar image

Here are the steps to establish a directory on an FTP server using C#:

  1. Create an instance of the FtpWebRequest class and specify the server URL.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://ftp.example.com/new_directory");
  1. Set the request method to "MKD" (make directory).
request.Method = WebRequestMethods.Ftp.MakeDirectory;
  1. Set the FTP credentials.
request.Credentials = new NetworkCredential("username", "password");
  1. Send the request and get the FTP server response.
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
  1. Get the status code from the response.
Console.WriteLine("Directory created: {0}", response.StatusDescription);
  1. Close the response.
response.Close();

The complete code:

FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://ftp.example.com/new_directory");
request.Method = WebRequestMethods.Ftp.MakeDirectory;
request.Credentials = new NetworkCredential("username", "password");

FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Console.WriteLine("Directory created: {0}", response.StatusDescription);

response.Close();
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-07-20 21:41:59 +0000

Seen: 21 times

Last updated: Jul 20 '23