static void Open(string [] Input) { if (Input == null) { Console.WriteLine("Invalid parameters"); return; } string User, Pass; Console.Write("login: "******"") { User = "******"; Pass = "******"; } else { Console.Write("password: "******"") { Pass = "******"; } } Client.Username = User; Client.Password = Pass; if (Input.Length >= 1) { Client.Hostname = Input[0]; } else { Client.Hostname = "localhost"; } if (Input.Length >= 2) { Client.Port = int.Parse(Input[1]); } else { Client.Port = 21; } if (Input.Length >= 3) { if (Input[2].ToLower() == "passive") { Client.Passive = true; } else { Client.Passive = false; } } Client.Disconnect(); Client.WorkDir = ""; Client.Connect(); }
/// <summary> /// ����Ftp /// </summary> /// <returns></returns> private FtpConnection FtpConn() { ftp=new FtpConnection(); ftp.Connect(this.FtpIP,this.FtpUserName,this.FtpPassord); return ftp; }
static void Main() { string Input, Command; string [] Parameters; Console.WriteLine("\r\n Welcome to NetFTP!\r\n ------------------"); Client = new FtpConnection(); Client.ReceivedReply += new FtpConnection.ReceivedReplyHandler(ReceivedReply); Client.Connected += new FtpConnection.ConnectedHandler(Connected); Client.Disconnected += new FtpConnection.DisconnectedHandler(Disconnected); Client.ConnectionFailed += new FtpConnection.ConnectionFailedHandler(ConnectionFailed); Client.CommandSent += new FtpConnection.CommandSentHandler(CommandSent); Console.WriteLine("\r\n FTP Client ready [type 'help' for help (duh)]"); Console.Write("\r\n>"); Input = Console.ReadLine(); while (!Input.ToLower().Equals("exit")) { Parameters = null; Input = Input.Trim(); if (Input.IndexOf(' ') >= 0) { Command = Input.Substring(0, Input.IndexOf(' ')).ToLower(); Parameters = RemoveRedundantItems(Input.Substring(Input.IndexOf(' ') + 1).Split(' ')); } else { Command = Input.ToLower(); } switch (Command) { case "help": Help(); break; case "open": Open(Parameters); break; case "dir": Dir(Parameters); break; case "cd": Cd(Parameters); break; case "cd..": ToUpDir(); break; case "status": Status(); break; case "sysinfo": SysInfo(); break; case "del": Delete(Parameters); break; case "md": MakeDir(Parameters); break; case "mkdir": MakeDir(Parameters); break; case "rd": RemoveDir(Parameters); break; case "ren": Rename(Parameters); break; case "chmod": ChMod(Parameters); break; case "custom": Custom(Parameters); break; case "upload": Upload(Parameters); break; case "download": Download(Parameters); break; case "disconnect": Client.Disconnect(); break; case "reconnect": Client.Disconnect(); Client.Connect(); break; default: Console.WriteLine("Invalid command"); break; } Console.Write(">"); Input = Console.ReadLine(); } Client.Disconnect(); }
/// <summary> /// 连接Ftp /// </summary> /// <returns></returns> private FtpConnection FtpConn() { ftp = new FtpConnection(); ftp.Connect(this.FtpIP, this.FtpUserName, this.FtpPassord); return(ftp); }