private static FtpServer StopServer(FtpServer ftpServer) { ftpServer.Start(); ftpServer.Stop(); return(ftpServer); }
private void StartUpFtpServer(string HostIP) { try { m_ftpServer.Stop(); ManagementObjectSearcher query = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'TRUE'"); ManagementObjectCollection nics = query.Get(); foreach (ManagementObject nic in nics) { { if (getIpBaseNum((nic["IPSubnet"] as String[])[0], (nic["IPAddress"] as String[])[0]) == getIpBaseNum((nic["IPSubnet"] as String[])[0], HostIP)) { m_ftpServer.PasvIPSetting = (nic["IPAddress"] as String[])[0]; break; } else { m_ftpServer.PasvIPSetting = null; } } } m_ftpServer.Start(); //Console.WriteLine("Press enter to exit..."); //Console.ReadLine(); //m_ftpServer.Stop(); } catch (System.Exception e) { NetDebuger.PrintErrorMessage("FATAL ERROR:" + e.Message); } }
static void Main(string[] args) { FtpServer f = new FtpServer(port: 21, enableIPv6: true, ipv6Port: 2121, logHeader: "UniFTP"); f.Config = new FtpConfig("D:\\Temp", welcome: new string[] { "By Ulysses" }); //Load configs... f.LoadConfigs(); //or add configs manually //f.AddUserGroup("test", AuthType.Password); //f.AddGroupRule("test", "/", "rwxrwxrwx"); //f.AddUser("root", "test", "test"); //Import SSL cert f.ImportCertificate("UniFTP.Open.pfx", null); //Log event f.OnLog += sender => Console.WriteLine(((FtpLogEntry)sender).ToString()); f.Config.LogInWelcome = new string[] { "Welcome back,Commander." }; //Add directory/file link f.AddLink("test", "M:\\ACGMusic", "/"); f.AddGroupRule("test", "/Music", "r-xr-xr-x"); f.Start(); Console.WriteLine("UniFTP Server Started!"); Console.ReadLine(); f.Stop(); //Save configs for next time f.SaveConfigs(); return; }
public bool Start(string rootDir, string ipserver) { if (_HasInit) { Console.WriteLine("FtpServer already start"); return(true); } ipself = ipserver; if (!Directory.Exists(rootDir)) { Directory.CreateDirectory(rootDir); } fsProvider = new DotNetFileSystemProvider(rootDir); if (_FtpServer != null) { _FtpThreadAutoResetEvent.Reset(); _FtpServer.Stop(); _FtpServer.Dispose(); } _FtpThread = new Thread(new ThreadStart(DoStart)); _FtpThread.Start(); return(true); }
public void StopFtp() { if (_client != null && _client.IsConnected) { _client.Disconnect(); } _ftpServer?.Stop(); }
public void Stop() { _HasInit = false; //_FtpThreadAutoResetEvent.Close(); //_FtpThreadAutoResetEvent.Dispose(); _FtpThreadAutoResetEvent.Set(); _FtpServer?.Stop(); }
public void GetShouldWorkWithNullPath() { var client = new FtpClient("localhost", 8888); var server = new FtpServer(8888, 100); server.Start(); client.Get(null, null); server.Stop(); }
public void ShutDownServer() { if (_ftpServer.IsActive()) { _ftpServer.Stop(); Console.WriteLine(@"Server shut down."); } else { Console.WriteLine(@"Server is not running!"); } }
private static void Main() { // Load server certificate var cert = new X509Certificate2("test.pfx"); AuthTlsCommandHandler.ServerCertificate = cert; // Only allow anonymous login var membershipProvider = new AnonymousMembershipProvider(new NoValidation()); // Use the .NET file system var fsProvider = new DotNetFileSystemProvider(Path.Combine(Path.GetTempPath(), "TestFtpServer")); // Use all commands from the FtpServer assembly and the one(s) from the AuthTls assembly var commandFactory = new AssemblyFtpCommandHandlerFactory(typeof(FtpServer).Assembly, typeof(AuthTlsCommandHandler).Assembly); // Initialize the FTP server using (var ftpServer = new FtpServer(fsProvider, membershipProvider, "127.0.0.1", Port, commandFactory) { DefaultEncoding = Encoding.ASCII, LogManager = new FtpLogManager(), }) { #if USE_FTPS_IMPLICIT // Use an implicit SSL connection (without the AUTHTLS command) ftpServer.ConfigureConnection += (s, e) => { var sslStream = new FixedSslStream(e.Connection.OriginalStream); sslStream.AuthenticateAsServer(cert); e.Connection.SocketStream = sslStream; }; #endif // Create the default logger var log = ftpServer.LogManager?.CreateLog(typeof(Program)); try { // Start the FTP server ftpServer.Start(); Console.WriteLine("Press ENTER/RETURN to close the test application."); Console.ReadLine(); // Stop the FTP server ftpServer.Stop(); } catch (Exception ex) { log?.Error(ex, "Error during main FTP server loop"); } } }
public void GetShouldWorkWithIncorrectPath() { var client = new FtpClient("localhost", 8888); var server = new FtpServer(8888, 100); string path = Directory.GetCurrentDirectory() + @"\ShouldBeDeleted.txt"; if (File.Exists(path)) { File.Delete(path); } server.Start(); client.Get(path, path); server.Stop(); }
public void Stop() { if (ftpServer != null) { ftpServer.Stop(); } try { webSocketServer.Stop(); } catch (Exception ex) { var log = LogHelper.GetLogger(this.GetType()); log.Error("Stop websocket server failed.", ex); } }
public void GetRequestShouldWorkCorrectly() { using (FileStream fileStream = File.OpenWrite(Directory.GetCurrentDirectory() + @"\TestData\GetTestData.txt")) { byte[] content = System.Text.Encoding.Default.GetBytes("Hello, World!"); fileStream.Write(content, 0, content.Length); } File.Delete(Directory.GetCurrentDirectory() + @"\TestData\GetResult.txt"); string path = Directory.GetCurrentDirectory() + @"\TestData\GetTestData.txt"; string resultPath = Directory.GetCurrentDirectory() + @"\TestData\GetResult.txt"; var client = new FtpClient("localhost", 8888); var server = new FtpServer(8888, 100); server.Start(); client.Get(path, resultPath); server.Stop(); byte[] trueResult = null; using (FileStream fileStream = File.OpenRead(path)) { trueResult = new byte[fileStream.Length]; fileStream.Read(trueResult, 0, trueResult.Length); } byte[] result = null; using (FileStream fileStream = File.OpenRead(resultPath)) { result = new byte[fileStream.Length]; fileStream.Read(result, 0, result.Length); } Assert.AreEqual(trueResult.Length, result.Length); for (int i = 0; i < trueResult.Length; i++) { Assert.AreEqual(trueResult[i], result[i]); } }
public void ListRequestShouldWorkCorrectly() { Directory.CreateDirectory(Directory.GetCurrentDirectory() + @"\TestData\directory_1"); Directory.CreateDirectory(Directory.GetCurrentDirectory() + @"\TestData\directory_2"); File.Create(Directory.GetCurrentDirectory() + @"\TestData\EmptyFile_1.txt"); File.Create(Directory.GetCurrentDirectory() + @"\TestData\EmptyFile_2.txt"); string path = Directory.GetCurrentDirectory() + @"\TestData"; string[] fileNames = Directory.GetFiles(path); string[] subdirectoryNames = Directory.GetDirectories(path); string[] directoryObjectNames = new string[fileNames.Length + subdirectoryNames.Length]; fileNames.CopyTo(directoryObjectNames, 0); subdirectoryNames.CopyTo(directoryObjectNames, fileNames.Length); Array.Sort(directoryObjectNames); var client = new FtpClient("localhost", 8888); var server = new FtpServer(8888, 100); server.Start(); var fileStructs = client.List(path); server.Stop(); fileStructs.Sort(); Assert.AreEqual(directoryObjectNames.Length, fileStructs.Count); for (int i = 0; i < directoryObjectNames.Length; i++) { Assert.AreEqual(directoryObjectNames[i], fileStructs[i].Name); bool isDir = Directory.Exists(directoryObjectNames[i]); Assert.AreEqual(isDir, fileStructs[i].IsDirectory); } }
public void TearDown() { _server.Stop(); }
public void Dispose() { server.Stop(); server.Dispose(); }