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 = "ShareX FTP client - " + account.Name; lblConnecting.Text = "Connecting to " + account.FTPAddress; TaskEx.Run(() => { Client.Connect(); }, () => { pConnecting.Visible = false; Refresh(); RefreshDirectory(); }); }
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(); }); }
private void FTPAccountAddButton_Click(object sender, EventArgs e) { FTPAccount acc = new FTPAccount(); Config.FTPAccountList.Add(acc); ucFTPAccounts.AddItem(acc); FTPSetup(Config.FTPAccountList); }
private void FTPAccountCloneButton_Click(object sender, EventArgs e) { FTPAccount src = ucFTPAccounts.AccountsList.Items[ucFTPAccounts.AccountsList.SelectedIndex] as FTPAccount; Config.FTPAccountList2.Add(src.Clone()); ucFTPAccounts.AccountsList.SelectedIndex = ucFTPAccounts.AccountsList.Items.Count - 1; FTPSetup(Config.FTPAccountList2); }
private void FTPAccountDuplicateButton_Click(object sender, EventArgs e) { FTPAccount src = (FTPAccount)ucFTPAccounts.lbAccounts.Items[ucFTPAccounts.lbAccounts.SelectedIndex]; FTPAccount clone = (FTPAccount)src.Clone(); Config.FTPAccountList.Add(clone); ucFTPAccounts.AddItem(clone); FTPSetup(Config.FTPAccountList); }
private void FTPAccountAddButton_Click(object sender, EventArgs e) { FTPAccount acc = new FTPAccount("New Account"); Config.FTPAccountList2.Add(acc); ucFTPAccounts.AccountsList.Items.Add(acc); ucFTPAccounts.AccountsList.SelectedIndex = ucFTPAccounts.AccountsList.Items.Count - 1; FTPSetup(Config.FTPAccountList2); }
private void FTPAccountsList_SelectedIndexChanged(object sender, EventArgs e) { int sel = ucFTPAccounts.AccountsList.SelectedIndex; if (Config.FTPAccountList2.HasValidIndex(sel)) { FTPAccount acc = Config.FTPAccountList2[sel]; ucFTPAccounts.SettingsGrid.SelectedObject = acc; } }
public FTPAccount GetFtpAcctActive() { FTPAccount acc = null; if (CheckFTPAccounts()) { acc = Config.FTPAccountList2[Config.FTPSelectedImage]; } return(acc); }
public void TestFTPAccountAsync(FTPAccount acc) { if (acc != null) { ucFTPAccounts.btnTest.Enabled = false; BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += new DoWorkEventHandler(bw_DoWorkTestFTPAccount); bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompletedTestFTPAccount); bw.RunWorkerAsync(acc); } }
private string GetURL(FtpListItem file) { if (file != null && file.Type == FtpFileSystemObjectType.File) { FTPAccount accountClone = Account.Clone(); accountClone.SubFolderPath = currentDirectory; accountClone.HttpHomePathAutoAddSubFolderPath = true; return(accountClone.GetUriPath(file.Name)); } return(null); }
public FTP(FTPAccount account) { this.Account = account; this.Client = new FtpClient(); switch (account.Protocol) { case FTPProtocol.FTPS: if (File.Exists(account.FtpsCertLocation)) { Client.SecurityProtocol = account.FtpsSecurityProtocol; Client.SecurityCertificates.Add(X509Certificate.CreateFromSignedFile(account.FtpsCertLocation)); } else { logger.WriteLine("Can't find ftps certificate (" + account.FtpsCertLocation + ")"); } break; default: Client.SecurityProtocol = FtpSecurityProtocol.None; break; } Client.Host = account.Host; Client.Port = account.Port; Client.DataTransferMode = account.IsActive ? TransferMode.Active : TransferMode.Passive; if (null != Uploader.ProxySettings) { IProxyClient proxy = Uploader.ProxySettings.GetProxyClient(); { if (proxy != null) { Client.Proxy = proxy; } } } Client.TransferProgress += new EventHandler <TransferProgressEventArgs>(OnTransferProgressChanged); Client.ConnectionClosed += new EventHandler <ConnectionClosedEventArgs>(Client_ConnectionClosed); }
public FTPClient2(FTPAccount account) { InitializeComponent(); lblStatus.Text = string.Empty; lvFTPList.SubItemEndEditing += new SubItemEndEditingEventHandler(lvFTPList_SubItemEndEditing); this.Account = account; FTPAdapter = new FTP(account); FTPAdapter.Client.ClientRequest += new EventHandler<FtpRequestEventArgs>(Client_ClientRequest); FTPAdapter.Client.ServerResponse += new EventHandler<FtpResponseEventArgs>(Client_ServerResponse); FTPAdapter.Client.OpenAsyncCompleted += new EventHandler<OpenAsyncCompletedEventArgs>(Client_OpenAsyncCompleted); pgAccount.SelectedObject = FTPAdapter.Account; this.Text = "FTP Client - " + account.Name; lblConnecting.Text = "Connecting to " + account.FTPAddress; FTPAdapter.Client.OpenAsync(account.UserName, account.Password); }
public FTPClientForm(FTPAccount account) { InitializeComponent(); Icon = ShareXResources.Icon; lblStatus.Text = string.Empty; lvFTPList.SubItemEndEditing += lvFTPList_SubItemEndEditing; Account = account; FTPAdapter = new FTP(account); FTPAdapter.Client.ClientRequest += Client_ClientRequest; FTPAdapter.Client.ServerResponse += Client_ServerResponse; FTPAdapter.Client.OpenAsyncCompleted += Client_OpenAsyncCompleted; pgAccount.SelectedObject = FTPAdapter.Account; Text = "FTP Client - " + account.Name; lblConnecting.Text = "Connecting to " + account.FTPAddress; FTPAdapter.Client.OpenAsync(account.Username, account.Password); }
public FTP(FTPAccount account, int bufferSize = 8192) { Account = account; Client = new FtpClient(account.Host, account.Port); Client.TcpBufferSize = bufferSize; if (account.Protocol == FTPProtocol.FTP || account.FtpsSecurityProtocol == FtpSecurityProtocol.None) { Client.SecurityProtocol = (Starksoft.Net.Ftp.FtpSecurityProtocol)FtpSecurityProtocol.None; } else { Client.SecurityProtocol = (Starksoft.Net.Ftp.FtpSecurityProtocol)account.FtpsSecurityProtocol; if (!string.IsNullOrEmpty(account.FtpsCertLocation) && File.Exists(account.FtpsCertLocation)) { Client.SecurityCertificates.Add(X509Certificate.CreateFromSignedFile(account.FtpsCertLocation)); } else { Client.ValidateServerCertificate += (sender, e) => e.IsCertificateValid = true; } } Client.DataTransferMode = account.IsActive ? TransferMode.Active : TransferMode.Passive; if (ProxyInfo.Current != null) { IProxyClient proxy = ProxyInfo.Current.GetProxyClient(); if (proxy != null) { Client.Proxy = proxy; } } Client.TransferProgress += OnTransferProgressChanged; Client.ConnectionClosed += Client_ConnectionClosed; }
public FTP(FTPAccount account) { this.Account = account; this.Client = new FtpClient(); switch (account.Protocol) { case FTPProtocol.FTPS: if (File.Exists(account.FtpsCertLocation)) { Client.SecurityProtocol = account.FtpsSecurityProtocol; Client.SecurityCertificates.Add(X509Certificate.CreateFromSignedFile(account.FtpsCertLocation)); } else logger.WriteLine("Can't find ftps certificate (" + account.FtpsCertLocation + ")"); break; default: Client.SecurityProtocol = FtpSecurityProtocol.None; break; } Client.Host = account.Host; Client.Port = account.Port; Client.DataTransferMode = account.IsActive ? TransferMode.Active : TransferMode.Passive; if (null != Uploader.ProxySettings) { IProxyClient proxy = Uploader.ProxySettings.GetProxyClient(); { if (proxy != null) { Client.Proxy = proxy; } } } Client.TransferProgress += new EventHandler<TransferProgressEventArgs>(OnTransferProgressChanged); Client.ConnectionClosed += new EventHandler<ConnectionClosedEventArgs>(Client_ConnectionClosed); }
public static void TestFTPAccount(FTPAccount account, bool silent) { string msg = string.Empty; string sfp = account.GetSubFolderPath(); 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 if (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 { //DateTime time = DateTime.Now; ftpClient.Test(sfp); 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 (!string.IsNullOrEmpty(msg)) { string ping = SendPing(account.Host, 3); if (!string.IsNullOrEmpty(ping)) { msg += "\n\nPing results:\n" + ping; } if (silent) { // Engine.MyLogger.WriteLine(string.Format("Tested {0} sub-folder path in {1}", sfp, account.ToString())); } else { //MessageBox.Show(msg, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } } break; } if (silent) { DebugHelper.WriteLine(string.Format("Tested {0} sub-folder path in {1}", sfp, account.ToString())); } else { MessageBox.Show(msg, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public void TestFTPAccountAsync(FTPAccount acc) { if (acc != null) { mZScreen.ucFTPAccounts.btnTest.Enabled = false; BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += new DoWorkEventHandler(bw_DoWorkTestFTPAccount); bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompletedTestFTPAccount); bw.RunWorkerAsync(acc); } }
private void sBwFetchlist() { if (Engine.ConfigUploaders.FTPAccountList2 != null) { mAcc = Engine.ConfigUploaders.FTPAccountList2[Engine.ConfigUploaders.FTPSelectedImage]; } bwRemoteViewer.ReportProgress((int)RemoteViewerTask.ProgressType.UPDATE_STATUS_BAR_TEXT, string.Format("Fetching files from {0}", mAcc.Name)); if (mAcc != null && !string.IsNullOrEmpty(mAcc.Host)) { FTPOptions fopt = new FTPOptions(); fopt.Account = mAcc; fopt.ProxySettings = Adapter.CheckProxySettings().GetWebProxy; mFTP = new FTPAdapter(fopt); List<string> files = FetchList(); if (files.Count > 0) { sBwViewFile(files[0]); } } }
public void TestFTPAccountAsync(FTPAccount acc) { if (acc != null) { ucFTPAccounts.btnTest.Enabled = false; BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += bw_DoWorkTestFTPAccount; bw.RunWorkerCompleted += bw_RunWorkerCompletedTestFTPAccount; bw.RunWorkerAsync(acc); } }
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 = "Connected!\r\nCreated folders:\r\n" + string.Join("\r\n", directories); } else { msg = "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 = "Connected!\r\nCreated folders:\r\n" + string.Join("\r\n", directories); } else { msg = "Connected!"; } } } } } } catch (Exception e) { msg = e.Message; } MessageBox.Show(msg, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); }
public static void TestFTPAccount(FTPAccount account, bool silent) { string msg = string.Empty; string sfp = account.GetSubFolderPath(); switch (account.Protocol) { case FTPProtocol.SFTP: try { using (SFTP sftp = new SFTP(account)) { if (!sftp.IsValidAccount) { msg = "An SFTP client couldn't be instantiated, not enough information.\r\nCould be a missing key file."; } else if (sftp.Connect()) { List<string> createddirs = new List<string>(); if (!sftp.DirectoryExists(sfp)) { createddirs = sftp.CreateMultiDirectory(sfp); } if (sftp.IsConnected) { msg = (createddirs.Count == 0) ? "Connected!" : "Connected!\r\nCreated folders:\r\n"; for (int x = 0; x <= createddirs.Count - 1; x++) { msg += createddirs[x] + "\r\n"; } msg += "\r\n\r\nPing results:\r\n " + SendPing(account.Host, 3); } } } } catch (Exception e) { msg = e.Message; } break; default: try { using (FTP ftpClient = new FTP(account)) { if (ftpClient.ChangeDirectory(sfp, true)) { msg = "Connected!\r\n\r\nPing results:\r\n" + SendPing(account.Host, 3); } } } catch (Exception e) { msg = e.Message; } break; } if (silent) { DebugHelper.WriteLine(string.Format("Tested {0} sub-folder path in {1}", sfp, account)); } else { MessageBox.Show(msg, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public static void TestFTPAccount(FTPAccount account, bool silent) { string msg = string.Empty; string sfp = account.GetSubFolderPath(); 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 if (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 { //DateTime time = DateTime.Now; ftpClient.Test(sfp); 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 (!string.IsNullOrEmpty(msg)) { string ping = SendPing(account.Host, 3); if (!string.IsNullOrEmpty(ping)) { msg += "\n\nPing results:\n" + ping; } if (silent) { // Engine.MyLogger.WriteLine(string.Format("Tested {0} sub-folder path in {1}", sfp, account.ToString())); } else { //MessageBox.Show(msg, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } } break; } if (silent) { DebugHelper.WriteLine(string.Format("Tested {0} sub-folder path in {1}", sfp, account.ToString())); } else { MessageBox.Show(msg, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public FTPOptions(FTPAccount acc, IWebProxy proxy) { this.Account = acc; this.ProxySettings = proxy; }
public FTPOptions(FTPAccount acc, IWebProxy proxy) { Account = acc; ProxySettings = proxy; }
public void TestFTPAccountAsync(FTPAccount acc) { if (acc != null) { ucFTPAccounts.btnTest.Enabled = false; TaskEx.Run(() => { TestFTPAccount(acc, false); }, () => { ucFTPAccounts.btnTest.Enabled = true; }); } }
public void AddFTPAccount(FTPAccount account) { if (account != null) { Config.FTPAccountList.Add(account); ucFTPAccounts.AddItem(account); FTPSetup(Config.FTPAccountList); } }
private void FTPAccountAddButton_Click(object sender, EventArgs e) { FTPAccount acc = new FTPAccount("New Account"); Config.FTPAccountList.Add(acc); ucFTPAccounts.AccountsList.Items.Add(acc); ucFTPAccounts.AccountsList.SelectedIndex = ucFTPAccounts.AccountsList.Items.Count - 1; FTPSetup(Config.FTPAccountList); }