Beispiel #1
0
        public List <string> CreateMultiDirectory(string path)
        {
            List <string> directoryList = new List <string>();

            IEnumerable <string> paths = FTPHelpers.GetPaths(path).Select(x => x.TrimStart('/'));

            foreach (string directory in paths)
            {
                if (!DirectoryExists(directory))
                {
                    CreateDirectory(directory);
                    directoryList.Add(directory);
                }
            }

            return(directoryList);
        }
        private void FillDirectories(string path)
        {
            List <string> paths = FTPHelpers.GetPaths(path);

            paths.Insert(0, "/");

            cbDirectoryList.Items.Clear();
            foreach (string directory in paths)
            {
                cbDirectoryList.Items.Add(directory);
            }

            if (cbDirectoryList.Items.Count > 0)
            {
                cbDirectoryList.SelectedIndex = cbDirectoryList.Items.Count - 1;
            }
        }
Beispiel #3
0
 public void CreateDirectory(string Path)
 {
     try
     {
         client.CreateDirectory(Path);
         DebugHelper.WriteLine("Created Directory: " + Path);
     }
     catch (SftpPathNotFoundException)
     {
         DebugHelper.WriteLine("Failed to create directory " + Path);
         DebugHelper.WriteLine("Attempting to fix...");
         CreateMultipleDirectorys(FTPHelpers.GetPaths(Path));
     }
     catch (SftpPermissionDeniedException)
     {
     }
 }
        public static void TestFTPAccount(FTPAccount account, bool silent)
        {
            string msg  = string.Empty;
            string sfp  = account.GetSubFolderPath();
            bool   succ = false;

            switch (account.Protocol)
            {
            case FTPProtocol.SFTP:
                SFTP sftp = new SFTP(account);
                if (!sftp.IsInstantiated)
                {
                    msg = "An SFTP client couldn't be instantiated, not enough information.\nCould be a missing key file.";
                }
                else
                {
                    sftp.Connect();
                    List <string> createddirs = new List <string>();
                    if (!sftp.DirectoryExists(sfp))
                    {
                        createddirs = sftp.CreateMultipleDirectorys(FTPHelpers.GetPaths(sfp));
                    }
                    if (sftp.IsConnected)
                    {
                        msg = (createddirs.Count == 0) ? "Connected!" : "Conected!\nCreated folders;\n";
                        for (int x = 0; x <= createddirs.Count - 1; x++)
                        {
                            msg += createddirs[x] + "\n";
                        }
                        msg += " \n\nPing results:\n " + SendPing(account.Host, 3);
                        sftp.Disconnect();
                    }
                }
                break;

            default:
                using (FTP ftpClient = new FTP(account))
                {
                    try
                    {
                        succ = ftpClient.Test(sfp);
                        if (succ)
                        {
                            msg = "Success!";
                        }
                    }
                    catch (Exception e)
                    {
                        if (e.Message.StartsWith("Could not change working directory to"))
                        {
                            try
                            {
                                ftpClient.MakeMultiDirectory(sfp);
                                ftpClient.Test(sfp);
                                msg = "Success!\nAuto created folders: " + sfp;
                            }
                            catch (Exception e2)
                            {
                                msg = e2.Message;
                            }
                        }
                        else
                        {
                            msg = e.Message;
                        }
                    }
                }

                if (succ && !string.IsNullOrEmpty(msg))
                {
                    string ping = SendPing(account.Host, 3);
                    if (!string.IsNullOrEmpty(ping))
                    {
                        msg += "\n\nPing results:\n" + ping;
                    }
                }
                break;
            }
            if (succ && silent)
            {
                DebugHelper.WriteLine(string.Format("Tested {0} sub-folder path in {1}", sfp, account.ToString()));
            }
            else if (succ)
            {
                MessageBox.Show(msg, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }