Exemplo n.º 1
0
        public bool SendByFTP(string sFile, out string sErr)
        {
            bool bRet = false;

            _error = null;
            FtpClient objFTP = Ftp.CreateFtpClient();

            if (objFTP.UploadFile(sFile, Path.Combine(Ftp.Folder, Path.GetFileName(sFile))))
            {
                bRet = true;
            }
            else
            {
                _error = objFTP.ErrorMessage;
            }
            sErr = _error;
            return(bRet);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 1. download files to workFolder.
        /// 2. call ImportFiles to process all files in workFolder.
        /// 3. move processed files to workFolder\backup.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="dest"></param>
        /// <param name="bSilent"></param>
        /// <returns></returns>
        public bool ReceiveFile(string name, DTDataDestination dest, bool bSilent)
        {
            bool bOK = false;

            if (ParametersOK(true))
            {
                int i;
                _error = null;
                if (TransferMethod == enumDTMethod.LAN)
                {
                    string[] sFiles = System.IO.Directory.GetFiles(LanFolder, string.Format(CultureInfo.InvariantCulture, "{0}_*.dt", name));
                    if (sFiles != null)
                    {
                        bOK = true;
                        for (i = 0; i < sFiles.Length; i++)
                        {
                            string tgt = Path.Combine(WorkFolder, System.IO.Path.GetFileName(sFiles[i]));
                            try
                            {
                                System.IO.File.Move(sFiles[i], tgt);
                            }
                            catch (Exception er)
                            {
                                _error = ExceptionLimnorDatabase.FormExceptionText(er, "ReceiveFile. Error moving file [{0}] to [{1}].", sFiles[i], tgt);
                                TraceLogClass.TraceLog.ShowMessageBox = !bSilent;
                                TraceLogClass.TraceLog.Log(er);
                                bOK = false;
                                break;
                            }
                        }
                    }
                }
                else if (TransferMethod == enumDTMethod.FTP)
                {
                    FtpClient objFTP = Ftp.CreateFtpClient();
                    if (objFTP.GetContents(Ftp.Folder))
                    {
                        FtpFileInfo[] sFiles = objFTP.FileList;
                        if (sFiles != null)
                        {
                            for (i = 0; i < sFiles.Length; i++)
                            {
                                if (IsDataFile(sFiles[i].Filename, name))
                                {
                                    if (objFTP.Download(WorkFolder, sFiles[i].Filename))
                                    {
                                        objFTP.DeleteFile(sFiles[i].Filename);
                                    }
                                    else
                                    {
                                        _error = string.Format(CultureInfo.InvariantCulture, "Cannot download file [{0}] from the FTP server [{1}]. {2}", sFiles[i].Filename, Ftp.Host, objFTP.ErrorMessage);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        _error = string.Format(CultureInfo.InvariantCulture, "Cannot get file list from the FTP server [{0}]. {1} ", Ftp.Host, objFTP.ErrorMessage);
                    }
                    bOK = string.IsNullOrEmpty(_error);
                    if (!bOK)
                    {
                        TraceLogClass.TraceLog.ShowMessageBox = !bSilent;
                        TraceLogClass.TraceLog.Log(new Exception(_error));
                    }
                }
            }
            bool bImport = ImportFiles(name, dest, bSilent);

            if (bOK)
            {
                bOK = bImport;
            }
            return(bOK);
        }