Пример #1
0
        static void Main()
        {
            // Press Ctrl+F5 (or go to Debug > Start Without Debugging) to run your app.
            Console.WriteLine("  Welcome to FTPClient \n");

            int running = 1;

            username = "";
            password = "";
            server   = "";
            LogFiles MyLogFile = new LogFiles();

            MyLogFile.StartLog();

            while (running == 1)
            {
                Console.WriteLine("Press 1 to log in, Press 2 to log in with saved information, 3 to exit");
                String response = Console.ReadLine();
                if (response == "1")
                {
                    //get credentials for user
                    Console.WriteLine("Enter your FTP server (localhost, an IP address, etc.) excluding 'ftp://'\n");
                    server = Console.ReadLine();
                    server = "ftp://" + server;
                    MyLogFile.WriteLog("ftp Server: " + server);
                    Console.WriteLine("Enter your FTP server username\n");
                    username = Console.ReadLine();
                    MyLogFile.WriteLog("ftp username: "******"Enter your FTP server password\n");
                    password = Console.ReadLine();

                    timeout = false;

                    System.Timers.Timer aTimer = new System.Timers.Timer();
                    aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
                    aTimer.Interval = 300000; // 5 min
                    aTimer.Enabled  = true;

                    while (timeout == false)
                    {
                        DisplayMenu();
                        timeout = GetResponce(username, password, server, "", MyLogFile);
                    }
                    //On Logout, clear all user credentials stored
                    username = "";
                    password = "";
                    server   = "";
                }
                else if (response == "3")
                {
                    running = 0;
                }
                else if (response == "2")
                {
                    //start up a SCI to access its file and decryption
                    ServerConnectionInformation conn = new ServerConnectionInformation();

                    //load the old info if it's there
                    bool test_use = conn.load_saved_info();
                    if (test_use == true)
                    {
                        Console.WriteLine("Logging in as User: "******" on Server: " + conn.getServer());
                        //if it was, set it to the program.cs info
                        username = conn.getUser();
                        password = conn.getPass();
                        server   = conn.getServer();

                        MyLogFile.WriteLog("ftp server: " + server);
                        MyLogFile.WriteLog("ftp username: "******"", MyLogFile);
                        }
                        //On Logout, clear all user credentials stored
                        username = "";
                        password = "";
                        server   = "";
                    }
                    else
                    {
                        Console.WriteLine("There was no valid saved connection information");
                    }
                }
                else
                {
                    continue;
                }
            }
            MyLogFile.EndLog();
        } // end Main()