zoukankan      html  css  js  c++  java
  • FTP上传代码

     /// <summary>
            /// 定时上传
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void timerFtp_Tick(object sender, EventArgs e)
            {
                DateTime Dtime = DateTime.Now;
                if (Dtime.Minute % this.Info.FTPJG == 0)
                {
                    try
                    {
                        if (this.ThreadSendFTPFile != null)
                        {
                            this.ThreadSendFTPFile.Abort();
                            this.ThreadSendFTPFile = null;
                        }
                        this.ThreadSendFTPFile = new Thread(FtpUp);
                        this.ThreadSendFTPFile.Start();
    
                    }
                    catch
                    {
    
                    }
                }
    
                //if (Dtime.Minute == 0)
                //{
                //    Dtime = Dtime.AddHours(-1);
                //}
    
            }
            #endregion
    
            #region ftp上传 FtpUp() void 方法
            private void FtpUp()
            {
                try
                {
                    string FilePath = Application.StartupPath + "\Upload\";
                    //判断上传文件家是否存在
                    DirectoryInfo Dir = new DirectoryInfo(FilePath);
                    if (Dir.Exists)
                    {
                        FTPClient FTP = new FTPClient(this.Sysinfo.FTPIP);
                        FTP.Login(this.Info.FTPUserID, this.Info.FTPUserPass);
                        foreach (string str in Directory.GetFiles(FilePath))
                        {
                            string FileName = Path.GetFileName(str);
                            if (File.Exists(FilePath + FileName))
                            {
                                try
                                {
                                    //for (int i = 0; i < FileName.Length; i++)
                                    //{
                                    FTP.ConnectMode = FTPConnectMode.PASV;
                                    FTP.TransferType = FTPTransferType.BINARY;
                                    FTP.Put(FilePath + FileName, this.Info.FTPRemotePath + FileName);
                                    File.Delete(FilePath + FileName);
                                    //this.Sta_State.Text = "文件:" + FileName + "传送成功";
                                    //} 
                                }
                                catch
                                {
                                    //this.Sta_State.Text = "文件:" + FileName + "传送失败";
                                }
                            }
                        }
                        FTP.Quit();
                    }
                    else
                    {
                        //Dir.CreateSubdirectory(FilePath);
                    }
                }
    
                catch { }
            }
    
  • 相关阅读:
    让x86的android模拟器能模拟arm架构系统
    婴儿补充微量元素
    asterisk 能打电话的配置
    SIP协议错误代码大全
    asterisk错误排查
    asterisk帮助与国内论坛
    win10 只要打开文件对话框就卡死解决方法
    分享到朋友圈实现
    跳转前暂停几秒js如何实现
    Github css加载失败,样式混乱解决办法
  • 原文地址:https://www.cnblogs.com/lierjie/p/4021527.html
Copyright © 2011-2022 走看看