private void ThreadRun() { Byte [] abData = new Byte[m_nBufferSize]; try { int nReceived = m_theSocket.GetStream().Read(abData, 0, m_nBufferSize); while (nReceived > 0) { m_theCommands.Process(abData); nReceived = m_theSocket.GetStream().Read(abData, 0, m_nBufferSize); } } catch (System.Net.Sockets.SocketException) { } catch (System.IO.IOException) { } FtpServerMessageHandler.SendMessage(m_nId, "Connection closed"); if (Closed != null) { Closed(this); } m_theSocket.Close(); }
private void ThreadRun() { m_socketListen = Assemblies.General.SocketHelpers.CreateTcpListener(m_nPort); if (m_socketListen != null) { m_socketListen.Start(); FtpServerMessageHandler.SendMessage(0, "FTP Server Started"); bool fContinue = true; while (fContinue) { System.Net.Sockets.TcpClient socket = null; try { socket = m_socketListen.AcceptTcpClient(); } catch (System.Net.Sockets.SocketException) { fContinue = false; } finally { if (socket == null) { fContinue = false; } else { socket.NoDelay = false; m_nId++; FtpServerMessageHandler.SendMessage(m_nId, "New connection"); SendAcceptMessage(socket).Wait(); InitialiseSocketHandler(socket); } } } } else { FtpServerMessageHandler.SendMessage(0, "Error in starting FTP server"); } }
public void Process(Byte [] abData) { string sMessage = System.Text.Encoding.ASCII.GetString(abData); sMessage = sMessage.Substring(0, sMessage.IndexOf('\r')); FtpServerMessageHandler.SendMessage(Id, sMessage); string sCommand; string sValue; int nSpaceIndex = sMessage.IndexOf(' '); if (nSpaceIndex < 0) { sCommand = sMessage.ToUpper(); sValue = ""; } else { sCommand = sMessage.Substring(0, nSpaceIndex).ToUpper(); sValue = sMessage.Substring(sCommand.Length + 1); } System.Diagnostics.Trace.WriteLine("#### command " + sCommand + "; sValue: " + sValue); FtpCommands.FtpCommandHandler handler = m_theCommandHashTable[sCommand] as FtpCommands.FtpCommandHandler; if (handler == null) { FtpServerMessageHandler.SendMessage(Id, string.Format("\"{0}\" : Unknown command", sCommand)); Assemblies.General.SocketHelpers.Send(Socket, "550 Unknown command\r\n"); } else { handler.Process(sValue); } }