예제 #1
0
        //确定 按钮
        private void button1_Click(object sender, EventArgs e)
        {
            //不让再次点击确定按钮
            button1.Enabled = false;

            error                  = false;
            progressbar            = 0;
            this.richTextBox1.Text = "";

            //建立线程
            thread = new Thread(new ThreadStart(getDataThread));
            thread.IsBackground = true;

            //获得日期,并转换其格式以满足需求
            String date = dateTimePicker1.Value.ToString();

            date = date.Split(' ')[0].Replace('/', '-');
            Console.WriteLine(date);
            filename = Cat.userName.Text + date;

            sftp.Connect();//建立服务器连接

            //开启线程
            thread.Start();
        }
예제 #2
0
파일: WelCome.cs 프로젝트: ShinEDL/Spyer
 public WelCome()
 {
     InitializeComponent();
     db   = new DB();
     sftp = new SFTP();
     sftp.Connect();
 }
예제 #3
0
파일: Report.cs 프로젝트: ShinEDL/Spyer
        //确定按钮
        private void button1_Click(object sender, EventArgs e)
        {
            //不让再次点击确定按钮
            button1.Enabled = false;
            //使按钮不可用
            button2.Enabled = false;
            button3.Enabled = false;
            button4.Enabled = false;

            error       = false;
            progressbar = 0;
            images      = new Image[4];
            arr.Clear();
            this.richTextBox1.Text = "";
            pictureBox1.Image      = null;
            pictureBox2.Image      = null;
            pictureBox3.Image      = null;
            pictureBox4.Image      = null;


            //建立线程
            thread1 = new Thread(new ThreadStart(getDataThread));
            thread2 = new Thread(new ThreadStart(getImageThread));
            thread1.IsBackground = true;
            thread2.IsBackground = true;

            //获得日期,并转换其格式以满足需求
            String date = dateTimePicker1.Value.ToString();

            date = date.Split(' ')[0].Replace('/', '-');
            Console.WriteLine(date);
            filename = Cat.userName.Text + date;

            //获得反馈编号
            num = comboBox1.Text.Trim();
            if (num == "请选择" || num == "" || num == null)
            {
                MessageBox.Show("没有选择编号!");
                error = true;
                return;
            }

            //状态显示
            label8.Text = db.getResult(filename, num);

            sftp.Connect();//建立服务器连接

            //开启线程
            thread1.Start();
            Thread.Sleep(1000);
            if (error == false)
            {
                thread2.Start();
            }
        }
예제 #4
0
파일: Screenshot.cs 프로젝트: ShinEDL/Spyer
        //获取图片线程操作
        private void getImageThread()
        {
            //初始化
            sftp.Connect();                                //与服务器建立连接
            MemoryStream ms;                               //内存区域的流,用来读取截图
            MyInvoke     mi = new MyInvoke(UpdateForm);    //窗体控件的线程间安全调用

            arr = sftp.GetFileList("/root/img", filename); //获取文件列表

            progressbar = 10;
            //判断如果没有相应的截图时,则报错
            if (arr.Count == 0)
            {
                MessageBox.Show("没有该日期的数据!");
                progressbar = 0;
                error       = true;
                return;
            }

            //先读取出第一个截图
            ms                = new MemoryStream(sftp.Get("/root/img/" + arr[0]));
            images            = new Image[arr.Count];
            images[0]         = Image.FromStream(ms);
            pictureBox1.Image = images[0];
            flag              = 0;
            ms.Close();
            progressbar = 12;


            //如果有更多图片,则一一读取
            if (arr.Count > 1)
            {
                for (int i = 1; i < arr.Count; i++)
                {
                    Console.WriteLine(arr[i]);
                    ms        = new MemoryStream(sftp.Get("/root/img/" + arr[i]));
                    images[i] = Image.FromStream(ms);
                    ms.Close();
                    if (progressbar >= 92)
                    {
                        progressbar = 92;
                    }
                    else
                    {
                        progressbar = progressbar + 4;
                    }
                }
            }
            sftp.Disconnect();    //断开服务器连接
            this.BeginInvoke(mi); //调用控件的安全线程
            progressbar = 100;
        }
예제 #5
0
        /// <summary>
        /// Function Name : SftpConnect()
        /// Description   : This method is used to create SFTP Connection.
        /// </summary>
        /// <returns>It returns true if connected and false if not connected.</returns>
        public Boolean SftpConnect()
        {
            Boolean isConnected = false;

            _objSftpClient.ConnectedEvent      += new SFTP.ConnectedDelegate(ConnectedEvent);
            _objSftpClient.StateChangedEvent   += new SFTP.StateChangedDelegate(StateChangedEvent);
            _objSftpClient.DisconnectedEvent   += new SFTP.DisconnectedDelegate(DisconnectedEvent);
            _objSftpClient.AttributesDataEvent += new SFTP.AttributesDataDelegate(AttributesDataEvent);
            _objSftpClient.ProgressEvent       += new SFTP.ProgressDelegate(ProgressEvent);
            _objSftpClient.LoopItemEvent       += new SFTP.LoopDelegate(LoopItemEvent);
            _objSftpClient.Hostname             = objAdpterSettings.Host;
            _objSftpClient.Login      = objAdpterSettings.UserName;
            _objSftpClient.Password   = objAdpterSettings.Password;
            _objSftpClient.Port       = objAdpterSettings.Port;
            _objSftpClient.Blocking   = true;
            _objSftpClient.LicenseKey = "NYWQ-KGCS-36UG-5SMZ";

            try
            {
                if (_objSftpClient.State == SFTP.States.Disconnected)
                {
                    _objSftpClient.Connect();
                    while (_objSftpClient.State == SFTP.States.Connecting)
                    {
                        Thread.Sleep(1000);
                    }
                }

                if (_objSftpClient.State == SFTP.States.Idle)
                {
                    isConnected = true;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error while process try to connect with SFTP .Error: " + ex.Message);
                throw ex;
            }

            return(isConnected);
        }
예제 #6
0
        private void FTPTestAccount(FTPAccount account)
        {
            string        msg         = "";
            string        remotePath  = account.GetSubFolderPath();
            List <string> directories = new List <string>();

            try
            {
                if (account.Protocol == FTPProtocol.FTP || account.Protocol == FTPProtocol.FTPS)
                {
                    using (FTP ftp = new FTP(account))
                    {
                        if (ftp.Connect())
                        {
                            if (!ftp.DirectoryExists(remotePath))
                            {
                                directories = ftp.CreateMultiDirectory(remotePath);
                            }

                            if (ftp.IsConnected)
                            {
                                if (directories.Count > 0)
                                {
                                    msg = Resources.UploadersConfigForm_TestFTPAccount_Connected_Created_folders + "\r\n" + string.Join("\r\n", directories);
                                }
                                else
                                {
                                    msg = Resources.UploadersConfigForm_TestFTPAccount_Connected_;
                                }
                            }
                        }
                    }
                }
                else if (account.Protocol == FTPProtocol.SFTP)
                {
                    using (SFTP sftp = new SFTP(account))
                    {
                        if (sftp.Connect())
                        {
                            if (!sftp.DirectoryExists(remotePath))
                            {
                                directories = sftp.CreateMultiDirectory(remotePath);
                            }

                            if (sftp.IsConnected)
                            {
                                if (directories.Count > 0)
                                {
                                    msg = Resources.UploadersConfigForm_TestFTPAccount_Connected_Created_folders + "\r\n" + string.Join("\r\n", directories);
                                }
                                else
                                {
                                    msg = Resources.UploadersConfigForm_TestFTPAccount_Connected_;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                msg = e.Message;
            }

            MessageBox.Show(msg, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
예제 #7
0
파일: SftpMgr.cs 프로젝트: nuevollc/Nuevo
        public bool GetFiles()
        {
            bool status = false;

            _sftp = new SFTP(m_sftpUserName, m_sftpKey);
            _sftp.EnableLogging();
            _sftp.HostAddress = m_sftpSite;
            _sftp.UserName = m_sftpSiteUserName;
            _sftp.SshKeyFile = m_identityFile;
            _sftp.SshPassphrase = @"t0y0ta69";
            try
            {
                try
                {
                    // connect
                    _sftp.Connect();

                }
                catch (KellermanSoftware.NetSFtpLibrary.Implementation.SftpException ke)
                {

                    LogMsg("NEXCEPTION:SftpMgr::_sftp.Connect():ECaught:" + ke.Message);

                }
                // get a directory list
                List<FTPFileInfo> rFiles = _sftp.GetAllFiles(m_sftpSiteRemoteFolder);

                // process the list
                foreach (FTPFileInfo file in rFiles)
                {
                    if (file.Equals(".") || file.Equals(".."))
                        continue;

                    string f = this.ParseFileName(file.FileName);

                    // if we got it, don't get it
                    if ( this.CheckDb(f) )
                        continue;

                    try
                    {
                        // get the file and put in the watch folder to be processed
                        _sftp.DownloadFile(m_moveToProcessFolder + f, file.FileName);

                        string newPlace = m_moveAfterProcessingFolder + f;
                        bool moved =_sftp.MoveFile(file.FileName, newPlace );

                        // update the database to indicate file has been downloaded
                        this.UpdateDb(f);

                    }
                    catch (SystemException se)
                    {
                        LogMsg("NEXCEPTION:SftpMgr::GetFile():ECaught::"+se.Message + se.StackTrace );
                    }

                }

                _sftp.Disconnect();
                _sftp.Dispose();

                status = true;

            }
            catch (SystemException se)
            {
                LogMsg("NEXCEPTION:SftpMgr::GetFile():ECaught:TryingToGetFile::" + se.Message);
            }

            return status;
        }
예제 #8
0
        public static void TestFTPAccount(FTPAccount account, bool silent)
        {
            string msg = string.Empty;
            string sfp = account.GetSubFolderPath();

            switch (account.Protocol)
            {
            case FTPProtocol.SFTP:
                SFTP sftp = new SFTP(account);
                if (!sftp.IsInstantiated)
                {
                    msg = "An SFTP client couldn't be instantiated, not enough information.\nCould be a missing key file.";
                }
                else if (sftp.Connect())
                {
                    List <string> createddirs = new List <string>();
                    if (!sftp.DirectoryExists(sfp))
                    {
                        createddirs = sftp.CreateMultipleDirectorys(FTPHelpers.GetPaths(sfp));
                    }
                    if (sftp.IsConnected)
                    {
                        msg = (createddirs.Count == 0) ? "Connected!" : "Conected!\nCreated folders;\n";
                        for (int x = 0; x <= createddirs.Count - 1; x++)
                        {
                            msg += createddirs[x] + "\n";
                        }
                        msg += " \n\nPing results:\n " + SendPing(account.Host, 3);
                        sftp.Disconnect();
                    }
                }
                break;

            default:
                using (FTP ftpClient = new FTP(account))
                {
                    try
                    {
                        //DateTime time = DateTime.Now;
                        ftpClient.Test(sfp);
                        msg = "Success!";
                    }
                    catch (Exception e)
                    {
                        if (e.Message.StartsWith("Could not change working directory to"))
                        {
                            try
                            {
                                ftpClient.MakeMultiDirectory(sfp);
                                ftpClient.Test(sfp);
                                msg = "Success!\nAuto created folders: " + sfp;
                            }
                            catch (Exception e2)
                            {
                                msg = e2.Message;
                            }
                        }
                        else
                        {
                            msg = e.Message;
                        }
                    }
                }

                if (!string.IsNullOrEmpty(msg))
                {
                    string ping = SendPing(account.Host, 3);
                    if (!string.IsNullOrEmpty(ping))
                    {
                        msg += "\n\nPing results:\n" + ping;
                    }

                    if (silent)
                    {
                        // Engine.MyLogger.WriteLine(string.Format("Tested {0} sub-folder path in {1}", sfp, account.ToString()));
                    }
                    else
                    {
                        //MessageBox.Show(msg, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                break;
            }
            if (silent)
            {
                DebugHelper.WriteLine(string.Format("Tested {0} sub-folder path in {1}", sfp, account.ToString()));
            }
            else
            {
                MessageBox.Show(msg, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
예제 #9
0
        public bool GetFiles()
        {
            bool status = false;

            _sftp = new SFTP(m_sftpUserName, m_sftpKey);
            _sftp.EnableLogging();
            _sftp.HostAddress   = m_sftpSite;
            _sftp.UserName      = m_sftpSiteUserName;
            _sftp.SshKeyFile    = m_identityFile;
            _sftp.SshPassphrase = @"t0y0ta69";
            try
            {
                try
                {
                    // connect
                    _sftp.Connect();
                }
                catch (KellermanSoftware.NetSFtpLibrary.Implementation.SftpException ke)
                {
                    LogMsg("NEXCEPTION:AMSSftpMgr::_sftp.Connect():ECaught:" + ke.Message);
                    return(status);
                }
                // get a directory list
                List <FTPFileInfo> rFiles = _sftp.GetAllFiles(m_sftpSiteRemoteFolder);

                // process the list
                foreach (FTPFileInfo file in rFiles)
                {
                    if (file.Equals(".") || file.Equals(".."))
                    {
                        continue;
                    }

                    string f = this.ParseFileName(file.FileName);

                    // if we got it, don't get it
                    if (this.CheckDb(f))
                    {
                        continue;
                    }

                    try
                    {
                        // get the file and put in the watch folder to be processed
                        _sftp.DownloadFile(m_moveToProcessFolder + f, file.FileName);

                        // if we're crunching it then do it
                        if (this.m_moveToCrunchFlag)
                        {
                            _sftp.DownloadFile(m_moveToCrunchFolder + f, file.FileName);
                        }

                        string newPlace = m_moveAfterProcessingFolder + f;
                        bool   moved    = _sftp.MoveFile(file.FileName, newPlace);
                        bool   dirDone  = _sftp.CreateDirectory("tested");

                        // update the database to indicate file has been downloaded
                        this.UpdateDb(f);
                    }
                    catch (SystemException se)
                    {
                        LogMsg("NEXCEPTION:AMSSftpMgr::GetFile():ECaught::" + se.Message + se.StackTrace);
                    }
                }

                _sftp.Disconnect();
                _sftp.Dispose();

                status = true;
            }
            catch (SystemException se)
            {
                LogMsg("NEXCEPTION:AMSSftpMgr::GetFile():ECaught:TryingToGetFile::" + se.Message);
            }

            return(status);
        } // getFile()