/// <summary> /// Waits for a connection from the server and then sets the timeout /// when the connection is made. /// </summary> internal virtual void AcceptConnection() { if (acceptedSock == null) { acceptedSock = sock.Accept(timeout); SetSocketTimeout(acceptedSock, timeout); log.Debug("AcceptConnection() succeeded"); } }
/// <summary> /// Set the remote server type /// </summary> /// <param name="system">SYST string</param> public void SetParser(string system) { parserDetected = false; this.system = system != null?system.Trim() : null; if (system != null) { if (system.ToUpper().StartsWith(WINDOWS_STR)) { log.Debug("Selected Windows parser"); parser = windows; } else if (system.ToUpper().IndexOf(UNIX_STR) >= 0 || system.ToUpper().IndexOf(AIX_STR) >= 0) { log.Debug("Selected UNIX parser"); parser = unix; } else if (system.ToUpper().IndexOf(VMS_STR) >= 0) { log.Debug("Selected VMS parser"); parser = vms; } else if (system.ToUpper().IndexOf(OS400_STR) >= 0) { log.Debug("Selected OS/400 parser"); parser = os400; } else { parser = unix; log.Warn("Unknown SYST '" + system + "' - defaulting to Unix parsing"); } } else { parser = unix; log.Debug("Defaulting to Unix parsing"); } }
/// <summary> Parse an array of raw file information returned from the /// FTP server /// /// </summary> /// <param name="files"> array of strings /// </param> /// <returns> array of FTPFile objects /// </returns> internal virtual FTPFile[] Parse(string[] files) { FTPFile[] temp = new FTPFile[files.Length]; // quick check if no files returned if (files.Length == 0) { return(temp); } int count = 0; for (int i = 0; i < files.Length; i++) { try { FTPFile file = parser.Parse(files[i]); // we skip null returns - these are duff lines we know about and don't // really want to throw an exception if (file != null) { temp[count++] = file; } } catch (FormatException ex) { log.Debug(ex.Message); if (rotateParsersOnFail && count == 0) { // first error, let's try swapping parsers RotateParsers(); FTPFile file = parser.Parse(files[i]); if (file != null) { temp[count++] = file; } } // rethrow else { throw ex; } } } FTPFile[] result = new FTPFile[count]; Array.Copy(temp, 0, result, 0, count); return(result); }
/// <summary> /// Log a message, checking for passwords /// </summary> /// <param name="msg"> /// message to log /// </param> /// <param name="command"> /// true if a response, false otherwise /// </param> internal virtual void Log(string msg, bool command) { if (msg.StartsWith(PASSWORD_MESSAGE)) { msg = PASSWORD_MESSAGE + " ********"; } log.Debug(msg); if (command) { if (CommandSent != null) { CommandSent(this, new FTPMessageEventArgs(msg)); } } else { if (ReplyReceived != null) { ReplyReceived(this, new FTPMessageEventArgs(msg)); } } }
/// <summary> Helper method for dumping a listing /// /// </summary> /// <param name="list"> directory listing to print /// </param> internal void Print(string[] list) { log.Debug("Directory listing:"); for (int i = 0; i < list.Length; i++) { log.Debug(list[i]); } log.Debug("Listing complete"); }