Exemplo n.º 1
0
        //备份到2号服务器
        private void vf_Ftp2(object a)
        {
            Tools.WriteLog("Log", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "进入FTP2");
            //检查是否有未上传的文件
            while (!ib_Ftp2Upload)
            {
                bool OK = false;
                //List<string> list = INIFile.ReadKeyValues("IfFtpUpLoad");
                List <string> list       = SysVisitor.Current.ReadKeyValues("IfFtpUpLoad");
                List <string> ls_Ftplist = ListToUploadList(list, "Ftp2");//获取待上传文件列表
                if (ls_Ftplist.Count > 0)
                {
                    OK = true;
                }             //有文件未上传

                //获取FTP2相关参数
                string IP       = SysVisitor.Current.of_GetMySysSet("FTP2", "IP");
                string UserID   = SysVisitor.Current.of_GetMySysSet("FTP2", "UserID");
                string Password = SysVisitor.Current.of_GetMySysSet("FTP2", "Password");
                string Path     = SysVisitor.Current.of_GetMySysSet("FTP2", "Path");
                string Port     = SysVisitor.Current.of_GetMySysSet("FTP2", "Port");
                FtpWeb Ftp      = new FtpWeb(IP, Path, UserID, Password);
                if (!Ftp.Connect())//FTP 不可用
                {
                    ib_Ftp2Upload = true;
                    Tools.WriteLog("error", "FTP2服务器不可用");
                    break;
                }
                if (OK)
                {
                    if (!Ftp.DirectoryExist(DateTime.Now.ToString("yyyy-MM-dd")))
                    {
                        Ftp.MakeDir(DateTime.Now.ToString("yyyy-MM-dd"));
                    }
                    Path = Path + @"\" + DateTime.Now.ToString("yyyy-MM-dd");
                    //FTP2文件上传
                    FtpWeb ftp   = new FtpWeb(IP, Path, UserID, Password);
                    int    value = 0;//计算上传成功总数
                    for (int i = 0; i < ls_Ftplist.Count; i++)
                    {
                        int j = ftp.Upload(ls_Ftplist[i].ToString());
                        if (j == 1)//上传成功
                        {
                            value++;
                        }
                        string str = SysVisitor.Current.of_GetMySysSet("IfFtpUpLoad", ls_Ftplist[i].ToString());
                        str = str.Substring(str.Length - 3, 1);
                        SysVisitor.Current.of_SetMySysSet("IfFtpUpLoad", ls_Ftplist[i].ToString(), str + ",0");//更新节点

                        string ls_sql = "delete from mysysset where itemtype='IfFtpUpLoad' and itemvalue='0,0'";
                        MyConfig.ExecuteNonQuery(ls_sql);
                    }
                    Tools.WriteLog("Ftp", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "FTP2已成功上传 " + value + " 个文件,剩余待上传个数:" + (ls_Ftplist.Count - value));
                }
                Thread.Sleep(60 * 1000);//等待60秒
            }
            return;
        }  //Getreport
Exemplo n.º 2
0
        private void button9_Click(object sender, EventArgs e)//测试FTP2连接
        {
            FtpWeb ftp = new FtpWeb(textBox13.Text.Trim(), textBox9.Text.Trim(), textBox12.Text.Trim(), textBox11.Text.Trim());

            if (ftp.Connect() != true)
            {
                MessageBox.Show("成功连接FTP服务器");
            }
            else
            {
                MessageBox.Show("连接失败,请检查用户名密码及路径");
            }
        }
Exemplo n.º 3
0
        private void button8_Click(object sender, EventArgs e)//测试FTP1连接
        {
            FtpWeb ftp = new FtpWeb(textBox4.Text.Trim(), textBox8.Text.Trim(), textBox5.Text.Trim(), textBox6.Text.Trim());

            if (ftp.Connect() == true)
            {
                MessageBox.Show("成功连接FTP服务器1");
            }
            else
            {
                MessageBox.Show("连接失败,请检查用户名密码及路径");
            }
        }
Exemplo n.º 4
0
        //备份到2号服务器
        private void vf_Ftp2(object a)
        {
            Tools.WriteLog("Log", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "进入FTP2");
            //检查是否有未上传的文件
            while (!ib_Ftp2Upload)
            {
                bool OK = false;
                //List<string> list = INIFile.ReadKeyValues("IfFtpUpLoad");
                List<string> list = SysVisitor.Current.ReadKeyValues("IfFtpUpLoad");
                List<string> ls_Ftplist = ListToUploadList(list, "Ftp2");//获取待上传文件列表
                if (ls_Ftplist.Count > 0)
                { OK = true; }//有文件未上传

                //获取FTP2相关参数
                string IP = SysVisitor.Current.of_GetMySysSet("FTP2", "IP");
                string UserID = SysVisitor.Current.of_GetMySysSet("FTP2", "UserID");
                string Password = SysVisitor.Current.of_GetMySysSet("FTP2", "Password");
                string Path = SysVisitor.Current.of_GetMySysSet("FTP2", "Path");
                string Port = SysVisitor.Current.of_GetMySysSet("FTP2", "Port");
                FtpWeb Ftp = new FtpWeb(IP, Path, UserID, Password);
                if (!Ftp.Connect())//FTP 不可用
                {
                    ib_Ftp2Upload = true;
                    Tools.WriteLog("error", "FTP2服务器不可用");
                    break;
                }
                if (OK)
                {
                    if (!Ftp.DirectoryExist(DateTime.Now.ToString("yyyy-MM-dd")))
                    {
                        Ftp.MakeDir(DateTime.Now.ToString("yyyy-MM-dd"));
                    }
                    Path = Path + @"\" + DateTime.Now.ToString("yyyy-MM-dd");
                    //FTP2文件上传
                    FtpWeb ftp = new FtpWeb(IP, Path, UserID, Password);
                    int value = 0;//计算上传成功总数
                    for (int i = 0; i < ls_Ftplist.Count; i++)
                    {
                        int j = ftp.Upload(ls_Ftplist[i].ToString());
                        if (j == 1)//上传成功
                        {
                            value++;
                        }
                        string str = SysVisitor.Current.of_GetMySysSet("IfFtpUpLoad", ls_Ftplist[i].ToString());
                        str = str.Substring(str.Length - 3, 1);
                        SysVisitor.Current.of_SetMySysSet("IfFtpUpLoad", ls_Ftplist[i].ToString(), str + ",0");//更新节点

                        string ls_sql = "delete from mysysset where itemtype='IfFtpUpLoad' and itemvalue='0,0'";
                        MyConfig.ExecuteNonQuery(ls_sql);
                    }
                    Tools.WriteLog("Ftp", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "FTP2已成功上传 " + value + " 个文件,剩余待上传个数:" + (ls_Ftplist.Count - value));
                }
                Thread.Sleep(60 * 1000);//等待60秒
            }
            return;
        }