softairhk

softairhk

  • NA
  • 115
  • 0

Make a FTP connector

Oct 6 2003 11:01 PM
Hello! I would like to make a FTP connector, I have finished the structure as listed as following, but some functions I need your help to finish them, please take a look on the following coding: 1) How to change the "Password" field to display ****** only? 2) Save button can save textBox1, textBox2, textBox3 inputted string by using Username to make a username.txt file to backup the inputted account? 3) Open button can open username.txt and paste on textBox1, textBox2, textBox3? 4) Connect button will check if textBox1, textBox2, textBox3 if empty or not, if empty then prompt an error message and focus on that field is emptry one. Now it can work to connect an FTP server, please try it. I wish someone can help me to make this FTP connector to be perfect. Thanks! using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Diagnostics; namespace LinkFTPSrv { /// /// Summary description for LinkFTP. /// public class LinkFTP : System.Windows.Forms.Form { private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.Label label3; private System.Windows.Forms.TextBox textBox3; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; private System.Windows.Forms.ToolTip toolTip1; private System.ComponentModel.IContainer components; private bool blnMoving = false; private int MouseDownX = 0; private System.Windows.Forms.Button button3; private System.Windows.Forms.Button button4; private int MouseDownY = 0; public LinkFTP() { // // Required for Windows Form Designer support // InitializeComponent(); this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MainFormMouseDown); this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.MainFormMouseUp); this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.MainFormMouseMove); // // TODO: Add any constructor code after InitializeComponent call // } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.textBox1 = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.textBox2 = new System.Windows.Forms.TextBox(); this.label3 = new System.Windows.Forms.Label(); this.textBox3 = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.button3 = new System.Windows.Forms.Button(); this.button4 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // textBox1 // this.textBox1.Location = new System.Drawing.Point(80, 8); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(152, 20); this.textBox1.TabIndex = 0; this.textBox1.Text = ""; this.toolTip1.SetToolTip(this.textBox1, "Username of FTP server "); // // label1 // this.label1.Location = new System.Drawing.Point(8, 8); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(64, 16); this.label1.TabIndex = 1; this.label1.Text = "Username:"; this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // label2 // this.label2.Location = new System.Drawing.Point(8, 40); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(64, 16); this.label2.TabIndex = 3; this.label2.Text = "Password:"; this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // textBox2 // this.textBox2.Location = new System.Drawing.Point(80, 40); this.textBox2.Name = "textBox2"; this.textBox2.Size = new System.Drawing.Size(152, 20); this.textBox2.TabIndex = 2; this.textBox2.Text = ""; this.toolTip1.SetToolTip(this.textBox2, "Password of FTP server"); // // label3 // this.label3.Location = new System.Drawing.Point(8, 72); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(32, 16); this.label3.TabIndex = 5; this.label3.Text = "Host:"; this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // textBox3 // this.textBox3.Location = new System.Drawing.Point(80, 72); this.textBox3.Name = "textBox3"; this.textBox3.Size = new System.Drawing.Size(232, 20); this.textBox3.TabIndex = 4; this.textBox3.Text = ""; this.toolTip1.SetToolTip(this.textBox3, "DNS or IP of FTP Server"); // // button1 // this.button1.Location = new System.Drawing.Point(176, 104); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(64, 24); this.button1.TabIndex = 6; this.button1.Text = "Cancel"; this.toolTip1.SetToolTip(this.button1, "Cancel connect to FTP"); this.button1.Click += new System.EventHandler(this.button1_Click); // // button2 // this.button2.Location = new System.Drawing.Point(248, 104); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(64, 24); this.button2.TabIndex = 7; this.button2.Text = "Connect"; this.toolTip1.SetToolTip(this.button2, "Connect Now"); this.button2.Click += new System.EventHandler(this.button2_Click); // // button3 // this.button3.Location = new System.Drawing.Point(248, 40); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(64, 24); this.button3.TabIndex = 9; this.button3.Text = "Save"; this.toolTip1.SetToolTip(this.button3, "Save an inputted account"); this.button3.Click += new System.EventHandler(this.button3_Click); // // button4 // this.button4.Location = new System.Drawing.Point(248, 8); this.button4.Name = "button4"; this.button4.Size = new System.Drawing.Size(64, 24); this.button4.TabIndex = 8; this.button4.Text = "Open"; this.toolTip1.SetToolTip(this.button4, "Open an saved account"); this.button4.Click += new System.EventHandler(this.button4_Click); // // LinkFTP // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(328, 141); this.Controls.Add(this.button3); this.Controls.Add(this.button4); this.Controls.Add(this.button2); this.Controls.Add(this.button1); this.Controls.Add(this.label3); this.Controls.Add(this.textBox3); this.Controls.Add(this.label2); this.Controls.Add(this.textBox2); this.Controls.Add(this.label1); this.Controls.Add(this.textBox1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.MaximizeBox = false; this.Name = "LinkFTP"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Connect to FTP"; this.ResumeLayout(false); } #endregion /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new LinkFTP()); } private void button1_Click(object sender, System.EventArgs e) { this.Close(); } private void button2_Click(object sender, System.EventArgs e) { string sID; string sPW; string sHost; string sFTP; string sHeader; string sColon; string sSym; //try //{ sID=textBox1.Text; sPW=textBox2.Text; sHost=textBox3.Text; sHeader="ftp://"; sColon=":"; sSym="@"; sFTP=sHeader+sID+sColon+sPW+sSym+sHost; Process.Start("IExplore.exe",sFTP); this.Close(); //} //catch //{ //MessageBox.Show("Username, Pasword, Host should not be empty"); //} } void MainFormMouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { if (e.Button == MouseButtons.Left) { blnMoving = true; MouseDownX = e.X; MouseDownY = e.Y; } } void MainFormMouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { if (e.Button == MouseButtons.Left) { blnMoving = false; } } void MainFormMouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { if( blnMoving ) { Point temp = new Point(0,0); temp.X = this.Location.X + (e.X - MouseDownX); temp.Y = this.Location.Y + (e.Y - MouseDownY); this.Location = temp; } } private void button4_Click(object sender, System.EventArgs e) { //Open an account from a text file. } private void button3_Click(object sender, System.EventArgs e) { //Save inputted field of textBox1, textBox2 and textBox3 into a text file. } } } fm Softair