[Extension FtpWebRequest] is "Create Directory" available?

Forge Component
Published on 2018-04-13 by Maycon Oleczinski
5 votes
Published on 2018-04-13 by Maycon Oleczinski

I can't find a "create directory" action in this wonderful tool, or am I overlooking it?


Or else you can use "File System" Extension for directory creation.

Thanks for your help.

I guess I can't. The only access I have to that file server is over ftp. File System indeed allows to create a dir, but I couldn't find this functionality over ftp in it. That's why I was searching for it in FtpWebRequest. Or did I overlook that in FS?

hitesh maran wrote:


Or else you can use "File System" Extension for directory creation.

I couldn't see how to make a directory with the existing code, however, since it is an extension, I was able to edit it and add my own MakeDirectory action.  Worked fine for me, however, the host name had to be prefixed with "ftp://subdomain.domain.com" before the URI was accepted.

        /// <summary>
        /// Make a directory on a remote FTP site.
        /// </summary>
        /// <param name="ssHost">Specifies the computer name, IP address, of the FTP server to which to connect. It must an URI (RFC 2396).</param>
        /// <param name="ssUsername">Username to be logged in to the Hostname.</param>
        /// <param name="ssPassword">Password for the provided Username</param>
        /// <param name="ssEnableSSL">Enables FTPS (FTP with SSL) for security.</param>
        /// <param name="ssDirectoryFullpath">Directory to create on the remote server.</param>
        /// <param name="ssStatusCode"></param>
        /// <param name="ssStatusDescription"></param>
        public void MssMakeDirectoryCommand(string ssHost, string ssUsername, string ssPassword, string ssDirectoryFullpath, bool ssEnableSSL, out string ssStatusCode, out string ssStatusDescription) {
            string uri = ssHost + ssDirectoryFullpath;
            FtpWebRequest reqFTP;
            // Create FtpWebRequest object from the Uri provided
            reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));

            if (ssEnableSSL)
                reqFTP.EnableSsl = true;

                ServicePointManager.ServerCertificateValidationCallback = ServicePointManager_ServerCertificateValidationCallback;

                X509Certificate cert = X509Certificate.CreateFromCertFile(@"C:\MyCertDir\MyCertFile.cer");
                X509CertificateCollection certCollection = new X509CertificateCollection();

                reqFTP.ClientCertificates = certCollection;

            // Provide the WebPermission Credintials
            reqFTP.Credentials = new NetworkCredential(ssUsername, ssPassword);
            // By default KeepAlive is true, where the control connection
            // is not closed after a command is executed.
            reqFTP.KeepAlive = false;
            // Specify the command to be executed.
            reqFTP.Method = WebRequestMethods.Ftp.MakeDirectory;
            // Specify the data transfer type.
            reqFTP.UseBinary = true;

            try {
                using (var RESPONSE = (FtpWebResponse) reqFTP.GetResponse()) {
                    ssStatusCode = RESPONSE.StatusCode.ToString();
                    ssStatusDescription = RESPONSE.StatusDescription;
            } catch (Exception ex) {
                ssStatusCode = "";
                ssStatusDescription = ex.Message;

        } // MssMakeDirectoryCommand