Пример #1
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(Math.Min(80, Console.LargestWindowWidth), Math.Min(60, Console.LargestWindowHeight));
            // Get the object used to communicate with the server.
            XML_Functions.Connection ftp_connection = new XML_Functions.Connection();


            try
            {
                XML_Functions.Create_XML_Settings_File();
                XML_Functions.Read_XML_Settings_File(ftp_connection);

                List <String> files = new List <String>();
                files.Add(@"//usr/configs/sfty.dat");
                files.Add(@"//usr/temp/pdrv.sys");
                files.Add(@"//usr/temp/pdrv.dat");

                Console.WriteLine(string.Format("New Connection to IP : {0}", ftp_connection.IP));
                Console.WriteLine(string.Format("Username : {0} , Password : {1}", ftp_connection.Username, ftp_connection.Password));

                // create an FTP client
                FtpClient client = new FtpClient(ftp_connection.IP);

                // if you don't specify login credentials, we use the "anonymous" user account
                client.Credentials = new NetworkCredential(ftp_connection.Username, ftp_connection.Password);

                // begin connecting to the server
                client.Connect();


                foreach (String file in files)
                {
                    if (client.FileExists(file))
                    {
                        client.DeleteFile(file);
                        Console.WriteLine(file + " deleted");
                    }
                }

                client.Disconnect();
                Unicorn.show();
                Thread.Sleep(500);
                //Console.ReadKey();
                // File.WriteAllText(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\errors.log", result);

                // FileStream txtfile = File.Create(@"C:\test.txt");
                //File.WriteAllText(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\errors.log", reader.ReadToEnd());
            }
            catch (Exception e)
            {
                Console.Write(e.Message);
                //Console.ReadKey();
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(Math.Min(80, Console.LargestWindowWidth), Math.Min(60, Console.LargestWindowHeight));
            // Get the object used to communicate with the server.
            XML_Functions.Connection ftp_connection = new XML_Functions.Connection();

            StringBuilder result = new StringBuilder();

            try
            {
                XML_Functions.Create_XML_Settings_File();
                XML_Functions.Read_XML_Settings_File(ftp_connection);


                Console.WriteLine(string.Format("New Connection to IP : {0}", ftp_connection.IP));
                Console.WriteLine(string.Format("Username : {0} , Password : {1}", ftp_connection.Username, ftp_connection.Password));


                Staubli_Folder_Structure.xml_info_files.controller_file.Localfilename  = ftp_connection.Path + "temp_controller.xml";
                Staubli_Folder_Structure.xml_info_files.arm_file.Localfilename         = ftp_connection.Path + "temp_arm.xml";
                Staubli_Folder_Structure.xml_info_files.val3version_file.Localfilename = ftp_connection.Path + "temp_val3version.xml";
                List <string> tempfiles = new List <string>();
                tempfiles.Add(Staubli_Folder_Structure.xml_info_files.arm_file.Localfilename);
                tempfiles.Add(Staubli_Folder_Structure.xml_info_files.controller_file.Localfilename);
                tempfiles.Add(Staubli_Folder_Structure.xml_info_files.val3version_file.Localfilename);

                // create an FTP client
                FtpClient client = new FtpClient(ftp_connection.IP);

                // if you don't specify login credentials, we use the "anonymous" user account
                client.Credentials = new NetworkCredential(ftp_connection.Username, ftp_connection.Password);

                // begin connecting to the server
                client.Connect();

                foreach (FtpListItem item in client.GetListing(Staubli_Folder_Structure.paths.config_path))
                {
                    if (item.Type == FtpFileSystemObjectType.File)
                    {
                        if (item.FullName.Contains("arm"))
                        {
                            if (item.FullName.Contains("cfx"))
                            {
                                Staubli_Folder_Structure.xml_info_files.arm_file.Ftpfilename = item.FullName;
                            }
                        }
                    }
                }

                //Console.WriteLine(Staubli_Folder_Structure.xml_info_files.controller_file.Localfilename + "  " + Staubli_Folder_Structure.xml_info_files.controller_file.Ftpfilename);
                if (client.FileExists(Staubli_Folder_Structure.xml_info_files.controller_file.Ftpfilename))
                {
                    client.DownloadFile(Staubli_Folder_Structure.xml_info_files.controller_file.Localfilename, Staubli_Folder_Structure.xml_info_files.controller_file.Ftpfilename);
                }
                if (client.FileExists(Staubli_Folder_Structure.xml_info_files.arm_file.Ftpfilename))
                {
                    client.DownloadFile(Staubli_Folder_Structure.xml_info_files.arm_file.Localfilename, Staubli_Folder_Structure.xml_info_files.arm_file.Ftpfilename);
                }
                if (client.FileExists(Staubli_Folder_Structure.xml_info_files.val3version_file.Ftpfilename))
                {
                    client.DownloadFile(Staubli_Folder_Structure.xml_info_files.val3version_file.Localfilename, Staubli_Folder_Structure.xml_info_files.val3version_file.Ftpfilename);
                }
                client.Disconnect();

                Staubli_Folder_Structure.xml_info_files.controller_file.ItemsList.Add(Staubli_Folder_Structure.xml_items.PowerHourCount);
                Staubli_Folder_Structure.xml_info_files.controller_file.ItemsList.Add(Staubli_Folder_Structure.xml_items.ControlerSerialNumber);

                Staubli_Folder_Structure.xml_info_files.arm_file.ItemsList.Add(Staubli_Folder_Structure.xml_items.ArmOrderNumber);
                Staubli_Folder_Structure.xml_info_files.arm_file.ItemsList.Add(Staubli_Folder_Structure.xml_items.RobotType);

                Staubli_Folder_Structure.xml_info_files.val3version_file.ItemsList.Add(Staubli_Folder_Structure.xml_items.Val3Version);

                XML_Functions.Read_XML_File_Item(Staubli_Folder_Structure.xml_info_files.controller_file);
                XML_Functions.Read_XML_File_Item(Staubli_Folder_Structure.xml_info_files.arm_file);
                XML_Functions.Read_XML_File_Item(Staubli_Folder_Structure.xml_info_files.val3version_file);


                Console.WriteLine("PowerHourCount           : " + Staubli_Folder_Structure.xml_items.PowerHourCount.Value);
                Console.WriteLine("Arm Order number         : " + Staubli_Folder_Structure.xml_items.ArmOrderNumber.Value);
                Console.WriteLine("Controler Serial number  : " + Staubli_Folder_Structure.xml_items.ControlerSerialNumber.Value);
                Console.WriteLine("Robottype                : " + Staubli_Folder_Structure.xml_items.RobotType.Value);
                Console.WriteLine("Val3Version              : " + Staubli_Folder_Structure.xml_items.Val3Version.Value);

                result.Append(Staubli_Folder_Structure.xml_items.PowerHourCount.Value + Environment.NewLine);
                result.Append(Staubli_Folder_Structure.xml_items.ArmOrderNumber.Value + Environment.NewLine);
                result.Append(Staubli_Folder_Structure.xml_items.ControlerSerialNumber.Value + Environment.NewLine);
                result.Append(Staubli_Folder_Structure.xml_items.RobotType.Value + Environment.NewLine);
                result.Append(Staubli_Folder_Structure.xml_items.Val3Version.Value + Environment.NewLine);

                XML_Functions.Delete_XML_Files(tempfiles);
                if (File.Exists(ftp_connection.Informationfilename))
                {
                    File.Delete(ftp_connection.Informationfilename);
                }
                File.WriteAllText(ftp_connection.Informationfilename, result.ToString());

                Unicorn.show();
                Thread.Sleep(500);
                // Console.ReadKey();
                // File.WriteAllText(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\errors.log", result);

                // FileStream txtfile = File.Create(@"C:\test.txt");
                //File.WriteAllText(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\errors.log", reader.ReadToEnd());
            }
            catch (Exception e)
            {
                Console.Write(e.Message);
                Console.ReadKey();
            }
        }
Пример #3
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(Math.Min(80, Console.LargestWindowWidth), Math.Min(60, Console.LargestWindowHeight));
            // Get the object used to communicate with the server.
            XML_Functions.Connection ftp_connection = new XML_Functions.Connection();


            try
            {
                XML_Functions.Create_XML_Settings_File();
                XML_Functions.Read_XML_Settings_File(ftp_connection);
                if (File.Exists(ftp_connection.Path + ftp_connection.Filename))
                {
                    File.Delete(ftp_connection.Path + ftp_connection.Filename);
                }
                if (File.Exists(ftp_connection.Path + "errors.log"))
                {
                    File.Delete(ftp_connection.Path + "errors.log");
                }
                Console.WriteLine(string.Format("New Connection to IP : {0}", ftp_connection.IP));
                Console.WriteLine(string.Format("Username : {0} , Password : {1}", ftp_connection.Username, ftp_connection.Password));
                Console.WriteLine(string.Format("Datapath : {0} , Filename : {1}", ftp_connection.Path, ftp_connection.Filename));

                StringBuilder result = new StringBuilder();

                string line = "";
                msgclass = ftp_connection.MsgClass;
                // This example assumes the FTP site uses anonymous logon.

                // create an FTP client
                FtpClient client = new FtpClient(ftp_connection.IP);

                // if you don't specify login credentials, we use the "anonymous" user account
                client.Credentials = new NetworkCredential(ftp_connection.Username, ftp_connection.Password);

                // begin connecting to the server
                client.Connect();

                client.DownloadFile(ftp_connection.Path + "errors.log", Staubli_Folder_Structure.files.logfile_path);

                client.Disconnect();

                if (File.Exists(ftp_connection.Path + "errors.log"))
                {
                    using (StreamReader reader = new StreamReader(ftp_connection.Path + "errors.log"))
                    {
                        result.Append(StaticText.header + Environment.NewLine);
                        while ((line = reader.ReadLine()) != null)
                        {
                            result.Append(string.Format(@"41860806845.6366;2;1;{1};1;""{0}"";;;;;;;;""07.05.2017 19:56:51"";"""";""""", line, msgclass) + Environment.NewLine);
                        }
                        // Console.WriteLine("Download Complete, status {0}", response.StatusDescription);

                        result.Append(StaticText.end + Environment.NewLine);
                    }
                }

                File.WriteAllText(ftp_connection.Path + ftp_connection.Filename, result.ToString());
                Unicorn.show();
                Thread.Sleep(500);
                // File.WriteAllText(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\errors.log", result);

                // FileStream txtfile = File.Create(@"C:\test.txt");
                //File.WriteAllText(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\errors.log", reader.ReadToEnd());
            }
            catch (Exception e)
            {
                String result = "";

                result += StaticText.header + Environment.NewLine;
                result += string.Format(@"41860806845.6366;2;1;{1};1;""{0}"";;;;;;;;""07.05.2017 19:56:51"";"""";""""", e.Message, msgclass) + Environment.NewLine;
                result += StaticText.end + Environment.NewLine;
                File.WriteAllText(ftp_connection.Path + ftp_connection.Filename, result);

                Console.Write(e.Message);
            }
        }
Пример #4
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(Math.Min(100, Console.LargestWindowWidth), Math.Min(60, Console.LargestWindowHeight));
            // Get the object used to communicate with the server.
            XML_Functions.Connection ftp_connection = new XML_Functions.Connection();

            List <string> files       = new List <string>();
            List <string> directories = new List <string>();


            string backupname = DateTime.Now.ToString("Y-yyyy M-MM D-dd hh_mm");

            try
            {
                XML_Functions.Create_XML_Settings_File();
                XML_Functions.Read_XML_Settings_File(ftp_connection);
                // create an FTP client

                Console.WriteLine(string.Format("New Connection to IP : {0}", ftp_connection.IP));
                Console.WriteLine(string.Format("Username : {0} , Password : {1}", ftp_connection.Username, ftp_connection.Password));

                // create an FTP client
                FtpClient client = new FtpClient(ftp_connection.IP);

                // if you don't specify login credentials, we use the "anonymous" user account
                client.Credentials = new NetworkCredential(ftp_connection.Username, ftp_connection.Password);

                // begin connecting to the server
                client.Connect();

                Stopwatch watch = new Stopwatch();
                watch.Start();
                // get a list of files and directories in the "/htdocs" folder
                foreach (string rootfolder in Staubli_Folder_Structure.paths.rootfolders)
                {
                    directories.Add(rootfolder);
                    foreach (FtpListItem item in client.GetListing(rootfolder))
                    {
                        if (item.Type == FtpFileSystemObjectType.File)
                        {
                            files.Add(item.FullName);
                        }
                        if (item.Type == FtpFileSystemObjectType.Directory)
                        {
                            directories.Add(item.FullName);
                            SearchFiles.getfiles(files, directories, item.FullName, client);
                        }
                    }
                }

                //Create Directories
                foreach (string directory in directories)
                {
                    //Console.WriteLine(ftp_connection.Path + "\\" + backupname + "\\" + directory);
                    System.IO.Directory.CreateDirectory(ftp_connection.Path + "\\" + backupname + "\\" + directory);
                }
                string temp = "";
                string path = "";
                //Put Files in to
                using (var progress = new ProgressBar())
                {
                    for (int i = 0; i < files.Count; i++)
                    {
                        temp = files[i].Split('/').Last();
                        path = files[i].Substring(0, files[i].Length - temp.Length - 1);

                        foreach (string directory in directories)
                        {
                            if (string.Equals(path, directory))
                            {
                                client.DownloadFile(ftp_connection.Path + "\\" + backupname + "\\" + path + "\\" + temp, files[i]);
                                progress.Report((double)i / files.Count);
                                progress.Report(files[i].Substring(0, Math.Min(files[i].Length, 65)));
                            }
                        }
                    }
                }

                Console.WriteLine("Backup in Folder : " + backupname + " created");
                client.Disconnect();
                watch.Stop();
                Console.WriteLine(string.Format("Benchmark : {0}", watch.ElapsedMilliseconds));
                Unicorn.show();
                Thread.Sleep(500);
                // Console.ReadKey();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.ReadKey();
            }
        }