public void Start() { var log = LogHelper.GetLogger(this.GetType()); // 启动FTP服务器 try { var membershipProvider = new AnonymousMembershipProvider(); var fsProvider = new DotNetFileSystemProvider(Path.Combine(Path.GetTempPath(), "TestFtpServer"), false); ftpServer = new FtpServer(fsProvider, membershipProvider, "127.0.0.1"); ftpServer.Start(); } catch (Exception ex) { log.Error("Create FtpServer failed.", ex); } // 启动Websocket服务器 try { // see: https://github.com/jjrdk/websocket-sharp webSocketServer = new WebSocketServer(null, int.Parse(webSocketPort)); webSocketServer.AddWebSocketService <SocketServer>("/Socket"); webSocketServer.Start(); } catch (Exception ex) { log.Error("Create websocket server failed.", ex); } }
private static FtpServer StopServer(FtpServer ftpServer) { ftpServer.Start(); ftpServer.Stop(); return(ftpServer); }
private void LaunchFtpServer() { Directory.CreateDirectory(@"root"); // allow only anonymous logins var membershipProvider = new AnonymousMembershipProvider(); // use %TEMP%/TestFtpServer as root folder var fsProvider = new DotNetFileSystemProvider("root", false); // Use all commands from the FtpServer assembly and NOT the one(s) from the AuthTls assembly var commandFactory = new AssemblyFtpCommandHandlerFactory(typeof(FtpServer).Assembly); // Initialize the FTP server _ftpServer = new FtpServer(fsProvider, membershipProvider, "127.0.0.1", FtpPort, commandFactory) { DefaultEncoding = Encoding.ASCII, // This can cause trouble. LogManager = new FtpLogManager(), }; // Start the FTP server _ftpServer.Start(); }
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 static void Main(string[] args) { IConfiguration conf = new ConfigurationBuilder() .AddJsonFile($"appsettings.json") .AddJsonFile($"appsettings.local.json", optional: true) .Build(); StorageProviderConfiguration.Init(conf); var _server = new FtpServer(new AzureFileSystemFactory(conf), conf); _server.NewConnection += nId => Console.WriteLine("Connection: {0} accepted", nId); // This is a sample worker implementation. Replace with your logic. Console.WriteLine("Information: FTPRole entry point called"); while (true) { if (_server.Started) { Thread.Sleep(10000); Console.WriteLine("Information: Server is alive"); } else { _server.Start(); Console.WriteLine("Control: Server starting"); } } }
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 OnetimeSetup() { port = new Random().Next(10000, 20000); var membershipProvider = new AnonymousMembershipProvider(); var fsProvider = new DotNetFileSystemProvider("ftp", false); ftpServer = new FtpServer(fsProvider, membershipProvider, "127.0.0.1", port, new AssemblyFtpCommandHandlerFactory(typeof(FtpServer).GetTypeInfo().Assembly)); ftpServer.Start(); }
public void GetFilesShouldListFiles() { server = GetFtpServer(); server.Start(); File.Create(Path.Combine(ftpHomeDirectory, "someFile.csv")).Dispose(); File.Create(Path.Combine(ftpHomeDirectory, "TestFile1.txt")).Dispose(); server.GetFiles(".").ShouldAllBeEquivalentTo(new[] { "someFile.csv", "TestFile1.txt" }); }
public FileServer(MountHandler parent, string host, int port, string user, string pass) { Parent = parent; var fsFact = new VirtualFsFactory(this); var mbFact = new FixedMemberProvider(user, pass); var ass = typeof(FtpServer).Assembly; var commands = new AssemblyFtpCommandHandlerFactory(ass); server = new FtpServer(fsFact, mbFact, host, port, commands); server.Start(); }
public void InitializaServer() { if (!_ftpServer.IsActive()) { _ftpServer.Start(); Console.WriteLine(@"Server initialized."); } else { Console.WriteLine(@"Server is already running!"); } }
public void Go(string[] args) { GetArgsAndConfig(args); if (_verbose) { ConsoleTraceListener conTrace = new ConsoleTraceListener(); Trace.Listeners.Add(conTrace); } _server = new FtpServer(new AzureFileSystemFactory()); _server.NewConnection += ServerNewConnection; _server.Start(); }
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 override void Run() { while (true) { if (_server.Started) { Thread.Sleep(10000); Trace.WriteLine("Server is alive.", "Information"); } else { _server.Start(); Trace.WriteLine("Server starting.", "Control"); } } }
public void Start() { var outPath = Path.Combine(Environment.CurrentDirectory, config.Path); outPath.EnsureDirectoryExistence(); log.Debug("Start FTP server: [{0}]", outPath); var membershipProvider = new AnonymousMembershipProvider(new NoValidation()); var provider = new DotNetFileSystemProvider(outPath, false); // Initialize the FTP server ftpServer = new FtpServer(provider, membershipProvider, "127.0.0.1", config.Port, new AssemblyFtpCommandHandlerFactory(typeof(FtpServer).GetTypeInfo().Assembly)); ftpServer.LogManager = new FtpLogManager(); // Start the FTP server ftpServer.Start(); }
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 Start() { var log = LogHelper.GetLogger(this.GetType()); // 启动FTP服务器 try { var path = HttpContext.Current.Server.MapPath("~/Upload/TestFtpServer"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var fsProvider = new RemoteFileSystemProvider(path, false); var membershipProvider = new AnonymousMembershipProvider(new NoValidation()); var ftpServer = new FtpServer( fsProvider, membershipProvider, "127.0.0.1", int.Parse(ftpPort), new AssemblyFtpCommandHandlerFactory(typeof(FtpServer).GetTypeInfo().Assembly) ); ftpServer.Start(); } catch (Exception ex) { log.Error("Create FtpServer failed.", ex); } // 启动Websocket服务器 try { // see: https://github.com/jjrdk/websocket-sharp webSocketServer = new WebSocketServer(null, int.Parse(webSocketPort)); webSocketServer.AddWebSocketService <SocketServer>("/Socket"); webSocketServer.Start(); } catch (Exception ex) { log.Error("Create websocket server failed.", ex); } }
public override void Run() { // This is a sample worker implementation. Replace with your logic. Trace.WriteLine("FTPRole entry point called", "Information"); while (true) { if (_server.Started) { Thread.Sleep(10000); Trace.WriteLine("Server is alive.", "Information"); } else { _server.Start(); Trace.WriteLine("Server starting.", "Control"); } } }
public void UploadingFileShouldUploadFile() { server = GetFtpServer(); server.Start(); var ftpRequest = (FtpWebRequest)WebRequest.Create(@"ftp://localhost:3435/someDirectory/someFile.csv"); ftpRequest.Method = WebRequestMethods.Ftp.UploadFile; using (var request = ftpRequest.GetRequestStream()) { using (var writer = new StreamWriter(request)) { writer.WriteLine("test"); } } server.GetFiles("someDirectory").ShouldAllBeEquivalentTo(new[] { "someFile.csv" }); }
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); } }
// private bool _HasError = true; private void DoStart() { try { _FtpServer = new FtpServer(fsProvider, membershipProvider, ipself); Console.WriteLine("FtpServer new a instance"); _FtpServer.Start(); //_HasError = false; _HasInit = true; FtpServerStatusChangeeHandler?.Invoke(CONNECT_STATUS.FTP_OK, "FTP_OK"); _FtpThreadAutoResetEvent.WaitOne(); Console.WriteLine("FtpServer start"); } catch (Exception e) { _HasInit = false; // _HasError = true; Console.WriteLine("FtpServer error " + e.ToString()); FtpServerStatusChangeeHandler?.Invoke(CONNECT_STATUS.FTP_NG, "FTP_NG"); } //_FtpServer?.stat }
public static void Main(string[] args) { var _server = new FtpServer(new AzureFileSystemFactory()); _server.NewConnection += nId => Console.WriteLine("Connection: {0} accepted", nId); // This is a sample worker implementation. Replace with your logic. Console.WriteLine("Information: FTPRole entry point called"); while (true) { if (_server.Started) { Thread.Sleep(10000); //Console.WriteLine("Information: Server is alive"); } else { _server.Start(); Console.WriteLine("Control: Server starting"); } } }
public void SetUp() { _server = new FtpServer(Port, MaxConnectionNumber); _server.Start(); }
private void Form1_Load(object sender, EventArgs e) { // Instantiate the writer _writer = new TextBoxStreamWriter(this.textBox1); // Redirect the out Console stream Console.SetOut(_writer); // FtpServer server = new FtpServer(); server.Start(); // chart_roll.Series.Clear(); chart_pitch.Series.Clear(); chart_yaw.Series.Clear(); chart_height.Series.Clear(); chart_battery.Series.Clear(); // serie_pitch_setpoint.ChartType = SeriesChartType.FastLine; serie_pitch_accel.ChartType = SeriesChartType.FastLine; serie_pitch_giro.ChartType = SeriesChartType.FastLine; serie_pitch_fusion.ChartType = SeriesChartType.FastLine; // chart_pitch.Series.Add(serie_pitch_setpoint); chart_pitch.Series.Add(serie_pitch_accel); chart_pitch.Series.Add(serie_pitch_giro); chart_pitch.Series.Add(serie_pitch_fusion); // serie_roll_setpoint.ChartType = SeriesChartType.FastLine; serie_roll_accel.ChartType = SeriesChartType.FastLine; serie_roll_giro.ChartType = SeriesChartType.FastLine; serie_roll_fusion.ChartType = SeriesChartType.FastLine; //chart_roll.Series.Add(serie_roll_setpoint); chart_roll.Series.Add(serie_roll_accel); chart_roll.Series.Add(serie_roll_giro); chart_roll.Series.Add(serie_roll_fusion); // serie_yaw_setpoint.ChartType = SeriesChartType.FastLine; serie_yaw_accel.ChartType = SeriesChartType.FastLine; serie_yaw_giro.ChartType = SeriesChartType.FastLine; serie_yaw_fusion.ChartType = SeriesChartType.FastLine; //chart_yaw.Series.Add(serie_yaw_setpoint); // chart_yaw.Series.Add(serie_yaw_accel); chart_yaw.Series.Add(serie_yaw_giro); //chart_yaw.Series.Add(serie_yaw_fusion); // serie_height_setpoint.ChartType = SeriesChartType.FastLine; serie_height_ultrasonic.ChartType = SeriesChartType.FastLine; chart_height.Series.Add(serie_height_setpoint); chart_height.Series.Add(serie_height_ultrasonic); // serie_battery.ChartType = SeriesChartType.FastLine; chart_battery.Series.Add(serie_battery); // //serie_battery2.ChartType = SeriesChartType.FastLine; //chart_battery.Series.Add(serie_battery2); this.backgroundWorker_battery.RunWorkerAsync(); //this.backgroundWorker_video_vertical.RunWorkerAsync(); //this.backgroundWorker_video_horizontal.RunWorkerAsync(); this.backgroundWorker_cameras.RunWorkerAsync(); this.backgroundWorker_telnet.RunWorkerAsync(); this.backgroundWorker_navboard.RunWorkerAsync(); }