Example #1
0
 /// <summary>
 /// 上传文件
 /// </summary>
 private void UpLoadFile()
 {
     _fileUploadRunning = true;
     //上传日志文件
     if (_curUploadLogFiles != null && _curUploadLogFiles.Length > 0)
     {
         foreach (FileInfo file in _curUploadLogFiles)
         {
             try
             {
                 string date = file.CreationTime.ToString("yyyy-MM-dd");
                 string path = string.Format("ServerLog/{0}/{1}/{2}", _seatId, file.CreationTime.Year, date);
                 //设置当前目录
                 _curFtpServices.FtpUpDown(_ftpIP, _ftpUserName, _ftpPassWord);
                 //创建目录
                 _curFtpServices.CheckDirectoryAndMakeMyWilson3(path);
                 //设置目录
                 _curFtpServices.FtpUpDown(_ftpIP + "/" + path + "/", _ftpUserName, _ftpPassWord);
                 //上传文件
                 _curFtpServices.Upload(file.FullName);
                 file.Delete();
             }
             catch //(Exception ex)
             {
             }
         }
     }
     _fileUploadRunning = false;
 }
Example #2
0
        /// <summary>
        /// 上传文件
        /// </summary>
        private void UpLoadFile()
        {
            _fileUploadRunning = true;
            //上传日志文件
            if (_curUploadLogFiles != null && _curUploadLogFiles.Length > 0)
            {
                log.Info("开始日志同步");
                foreach (FileInfo file in _curUploadLogFiles)
                {
                    try
                    {
                        string date = file.CreationTime.ToString("yyyy-MM-dd");
                        string path = string.Format("ClientLog/{0}/{1}/{2}", _curClientCode, file.CreationTime.Year, date);

                        if (file.DirectoryName != _curPhotoConfig.LogSavePath)
                        {
                            path = System.IO.Path.Combine(path, file.Directory.Name);
                        }
                        //设置当前目录
                        _curFtpServices.FtpUpDown(_curPhotoConfig.FtpIp, _curPhotoConfig.FtpUserName, _curPhotoConfig.FtpPassWord);
                        //创建目录
                        // if(Directory. _curPhotoConfig.LogSavePath!=file.Directory.Parent)
                        _curFtpServices.CheckDirectoryAndMakeMyWilson3(path);
                        //设置目录
                        _curFtpServices.FtpUpDown(_curPhotoConfig.FtpIp + "/" + path + "/", _curPhotoConfig.FtpUserName, _curPhotoConfig.FtpPassWord);
                        //上传文件

                        _curFtpServices.Upload(file.FullName);
                        log.Info("上传日志:" + file.FullName);
                        file.Delete();
                        ShowUpLoadInfo(string.Format("日志{0}上传成功。", file.FullName));
                    }
                    catch (Exception ex)
                    {
                        log.Error("上传日志文件失败:" + file.FullName + "。" + ex.Message);
                    }
                }
            }
            //上传照片文件
            if (_curUploadJpgFiles != null && _curUploadJpgFiles.Length > 0)
            {
                //ftp上传文件
                log.Info("开始照片同步");
                foreach (FileInfo file in _curUploadJpgFiles)
                {
                    try
                    {
                        string date = file.CreationTime.ToString("yyyy-MM-dd");
                        string path = string.Format("Photo/{0}/{1}/{2}", _curClientCode, file.CreationTime.Year, date);
                        //设置当前目录
                        _curFtpServices.FtpUpDown(_curPhotoConfig.FtpIp, _curPhotoConfig.FtpUserName, _curPhotoConfig.FtpPassWord);
                        //创建目录
                        _curFtpServices.CheckDirectoryAndMakeMyWilson3(path);
                        //设置目录
                        _curFtpServices.FtpUpDown(_curPhotoConfig.FtpIp + "/" + path + "/", _curPhotoConfig.FtpUserName, _curPhotoConfig.FtpPassWord);
                        log.Info("上传照片路径:" + _curPhotoConfig.FtpIp + "/" + path + "/");
                        //上传文件
                        _curFtpServices.Upload(file.FullName);
                        log.Info("上传照片:" + file.FullName);
                        if (SaveImgInfo(file.Name, path, _curClientCode))
                        {
                            file.Delete();
                            log.Info("删除照片:" + file.FullName);
                        }
                        //log.Info("调用服务写ftp文件路径完成。");
                        ShowUpLoadInfo(string.Format("照片{0}上传成功。", file.FullName));
                    }
                    catch (Exception ex)
                    {
                        log.Error("上传日志文件失败:" + file.FullName + "。" + ex.Message);
                    }
                }
                log.Info("文件同步结束");
                _curUploadJpgFiles = null;
            }
            _fileUploadRunning = false;
        }