Exemplo n.º 1
0
        public void Download(string destPath, string srcFilePath, bool retryOnErr = false)
        {
            Assert(Uri.IsWellFormedUriString(srcFilePath, UriKind.Relative));

            string tmpFile = Path.GetTempFileName();

            FluentFTP.FtpVerify flags = FluentFTP.FtpVerify.Throw | FluentFTP.FtpVerify.OnlyChecksum;
            flags |= FluentFTP.FtpVerify.Retry;

            using (var ftpClient = CreateFtpClient())
                try
                {
                    ftpClient.Connect();
                    ftpClient.DownloadFile(tmpFile, srcFilePath, verifyOptions: flags);
                }
                catch (FluentFTP.FtpException ex)
                {
                    throw ex.InnerException ?? ex;
                }

            using (new AutoReleaser(() => File.Delete(tmpFile)))
            {
                string decFilePath = DecodeFile(tmpFile);

                using (FileLocker.Lock(destPath))
                {
                    if (File.Exists(destPath))
                    {
                        File.Delete(destPath);
                    }

                    File.Move(decFilePath, destPath);
                }
            }
        }
Exemplo n.º 2
0
        public void Download(string destFolder, IEnumerable <string> srcURLs, bool retryOnErr = false)
        {
            Assert(!srcURLs.Any(s => Uri.IsWellFormedUriString(s, UriKind.Relative) == false));

            string tmpDir = Path.GetTempPath();

            FluentFTP.FtpVerify flags = FluentFTP.FtpVerify.Throw | FluentFTP.FtpVerify.OnlyChecksum;
            flags |= FluentFTP.FtpVerify.Retry;

            using (var ftpClient = CreateFtpClient())
                try
                {
                    ftpClient.Connect();
                    ftpClient.DownloadFiles(tmpDir, srcURLs, verifyOptions: flags, errorHandling: FluentFTP.FtpError.Throw);
                }
                catch (FluentFTP.FtpException ex)
                {
                    throw ex.InnerException ?? ex;
                }


            foreach (string src in srcURLs)
            {
                string srcFile = Path.GetFileName(src);
                string dlFile  = Path.Combine(tmpDir, srcFile);

                string decFilePath = DecodeFile(dlFile);

                string destPath = Path.Combine(destFolder, srcFile);

                using (FileLocker.Lock(destPath))
                {
                    if (File.Exists(destPath))
                    {
                        File.Delete(destPath);
                    }

                    File.Move(decFilePath, destPath);
                }

                File.Delete(dlFile);
            }
        }
Exemplo n.º 3
0
        public void Upload(string destFilePath, string srcFilePath, bool retryOnErr = false)
        {
            Assert(Uri.IsWellFormedUriString(destFilePath, UriKind.Relative));

            using (var ftpClient = CreateFtpClient())
            {
                string encFilePath = EncodeFile(srcFilePath);

                FluentFTP.FtpVerify flags = FluentFTP.FtpVerify.Throw | FluentFTP.FtpVerify.OnlyChecksum;
                flags |= FluentFTP.FtpVerify.Retry;

                using (new AutoReleaser(() => File.Delete(encFilePath)))
                    try
                    {
                        ftpClient.Connect();
                        ftpClient.UploadFile(encFilePath, destFilePath, createRemoteDir: true, verifyOptions: flags);
                    }
                    catch (FluentFTP.FtpException ex)
                    {
                        throw ex.InnerException ?? ex;
                    }
            }
        }
Exemplo n.º 4
0
        public void Upload(string destDir, IEnumerable <string> srcPaths, bool retryOnErr = false)
        {
            Assert(Uri.IsWellFormedUriString(destDir, UriKind.Relative));

            List <FileInfo> files = new List <FileInfo>();

            foreach (string src in srcPaths)
            {
                string tmpFile  = EncodeFile(src);
                string destPath = Path.Combine(Path.GetDirectoryName(tmpFile), Path.GetFileName(src));

                if (File.Exists(destPath))
                {
                    File.Delete(destPath);
                }

                File.Move(tmpFile, destPath);
                files.Add(new FileInfo(destPath));
            }

            FluentFTP.FtpVerify flags = FluentFTP.FtpVerify.Throw | FluentFTP.FtpVerify.OnlyChecksum;
            flags |= FluentFTP.FtpVerify.Retry;

            using (var ftpClient = CreateFtpClient())
                using (new AutoReleaser(() => files.ForEach((fi) => fi.Delete())))
                    try
                    {
                        ftpClient.Connect();
                        ftpClient.UploadFiles(files, destDir, createRemoteDir: true,
                                              verifyOptions: flags, errorHandling: FluentFTP.FtpError.Throw);
                    }
                    catch (FluentFTP.FtpException ex)
                    {
                        throw ex.InnerException ?? ex;
                    }
        }