public FTPClientForm(FTPAccount account) { InitializeComponent(); Icon = ShareXResources.Icon; lblStatus.Text = string.Empty; lvFTPList.SubItemEndEditing += lvFTPList_SubItemEndEditing; FtpTrace.AddListener(new TextBoxTraceListener(txtDebug)); Account = account; Client = new FTP(account); pgAccount.SelectedObject = Client.Account; Text = Resources.FTPClientForm_FTPClientForm_ShareX_FTP_client + " - " + account.Name; lblConnecting.Text = string.Format(Resources.FTPClientForm_FTPClientForm_Connecting_to__0_, account.FTPAddress); TaskEx.Run(() => { Client.Connect(); }, () => { pConnecting.Visible = false; Refresh(); RefreshDirectory(); }); }
public static void TestFTPAccount(FTPAccount account) { string msg = string.Empty; string remotePath = account.GetSubFolderPath(); List<string> directories = new List<string>(); try { if (account.Protocol == FTPProtocol.FTP || account.Protocol == FTPProtocol.FTPS) { using (FTP ftp = new FTP(account)) { if (ftp.Connect()) { if (!ftp.DirectoryExists(remotePath)) { directories = ftp.CreateMultiDirectory(remotePath); } if (ftp.IsConnected) { if (directories.Count > 0) { msg = Resources.UploadersConfigForm_TestFTPAccount_Connected_Created_folders + "\r\n" + string.Join("\r\n", directories); } else { msg = Resources.UploadersConfigForm_TestFTPAccount_Connected_; } } } } } else if (account.Protocol == FTPProtocol.SFTP) { using (SFTP sftp = new SFTP(account)) { if (sftp.Connect()) { if (!sftp.DirectoryExists(remotePath)) { directories = sftp.CreateMultiDirectory(remotePath); } if (sftp.IsConnected) { if (directories.Count > 0) { msg = Resources.UploadersConfigForm_TestFTPAccount_Connected_Created_folders + "\r\n" + string.Join("\r\n", directories); } else { msg = Resources.UploadersConfigForm_TestFTPAccount_Connected_; } } } } } } catch (Exception e) { msg = e.Message; } MessageBox.Show(msg, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information); }