Exemplo n.º 1
0
        static void Main(string[] args)
        {
            FTPHelper lFtp = new FTPHelper();

            lFtp.UsePassive = false;
            lFtp.LoadFromAppConfig();
            lFtp.ChangeDir("/");


            MemoryStream ms = new MemoryStream();

            if (lFtp.Connected)
            {
                List <string> lList = lFtp.GetFileList(".xml");
                foreach (string i in lList)
                {
                    Console.WriteLine(i);
                    //lFtp.DownloadFile(@"c:\" + Path.GetFileName(i), "/", Path.GetFileName(i), 1024);
                }
            }
            else
            {
                Console.WriteLine("FTP not Connected!");
            }
        }
Exemplo n.º 2
0
        private void 图片转换测试ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SystemConfig config = StaticCacheManager.GetConfig <SystemConfig>();

            this.notifyIcon1.Text = "1、正在开始查找照片,请稍候...";
            System.Threading.Thread.Sleep(1000);
            if (this.CheckNeedProcess(config))
            {
                this.notifyIcon1.Text = "2、正在准备打包照片,请稍候...";
                string filename = this.ZipFiles(config);
                this.notifyIcon1.Text = "3、正在准备上传到FTP,请稍候...";

                try
                {
                    FTPHelper ftp = new FTPHelper(config.FtpUrl, config.FtpName, config.FtpPassword);
                    //ftp.Connect(config.FtpUrl, config.FtpName, config.FtpPassword);
                    int perc = 0;
                    //int tmp1 = filename.LastIndexOf("/");
                    // int tmp2 = filename.LastIndexOf("\\");
                    if (config.FtpFolder.Trim().Length > 0)
                    {
                        ftp.ChangeDir(config.FtpFolder);
                    }
                    string name = filename.Substring(filename.LastIndexOf("\\") + 1);
                    ftp.OpenUpload(filename, name);
                    while (ftp.DoUpload() > 0)
                    {
                        perc = (int)((ftp.BytesTotal * 100) / ftp.FileSize);
                        this.notifyIcon1.Text = String.Format("\r上传: {0}/{1} {2}%",
                                                              ftp.BytesTotal, ftp.FileSize, perc);
                    }

                    this.notifyIcon1.Text = "4、上传到FTP成功!";
                    FileHelper.CutFolder2Another(config.MonitorPath, Path.Combine(config.BakPath, System.DateTime.Now.ToString("yyyyMMddHHmmss")));
                    this.notifyIcon1.Text = "5、删除并备份文件,顺利完成本次上传!";
                }
                catch (Exception ex)
                {
                    this.notifyIcon1.Text = "4、上传到FTP被中断,错误信息请看日志!";
                    this.CreateLog(ex.ToString());
                }
            }
            else
            {
                this.notifyIcon1.Text = "5、没有需要上传的照片!";
            }
        }