예제 #1
0
        public static UploaderFile[] CreateUploaders(
            this DirectoryInfo directoryHD,
            my.Ftp.DirectoryInfo directoryFTP,
            string searchPattern,
            bool recursive = false,
            CancellationTokenSource cancellation = null)
        {
            List <UploaderFile> uploaders = new List <UploaderFile>();

            if (directoryHD.Exists)
            {
                foreach (FileInfo fileHD in directoryHD.GetFiles(searchPattern, recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly))
                {
                    UploaderFile uploderFile = fileHD.CreateUploader(directoryFTP);
                    if (uploderFile != null)
                    {
                        uploaders.Add(uploderFile);
                    }

                    if (null != cancellation && cancellation.IsCancellationRequested)
                    {
                        throw new OperationCanceledException();
                    }
                }
            }

            return(uploaders.ToArray());
        }
예제 #2
0
        public void UpFileSync_file_exists_yes()
        {
            Ftp.DirectoryInfo ftpDir  = new Ftp.DirectoryInfo(Constants.Ftp.FTP_TestServer, "HDFtp/Upload");
            Ftp.FileInfo      ftpFile = new Ftp.FileInfo(ftpDir, "UploadTestFile");
            UploaderFile      uf      = new UploaderFile(ftpFile, Constants.HD.Files.File_1_1);

            uf.StartUpload(async: false);

            byte[] file_ftp = IO.File.ReadAllBytes("C:\\temp\\HDFtp\\Upload\\UploadTestFile");
            byte[] file_hd  = IO.File.ReadAllBytes(Constants.HD.Files.File_1_1.FullName);

            Assert.IsTrue(StructuralComparisons.StructuralEqualityComparer.Equals(file_ftp, file_hd));
        }
예제 #3
0
        public void UpFileSync_file_exists_no()
        {
            Ftp.DirectoryInfo ftpDir  = new Ftp.DirectoryInfo(Constants.Ftp.FTP_TestServer, "HDFtp/Upload");
            Ftp.FileInfo      ftpFile = new Ftp.FileInfo(ftpDir, "UploadTestFile");

            try
            {
                UploaderFile uf = new UploaderFile(ftpFile, Constants.HD.Files.NotExists);
                uf.StartUpload(async: false);
                Assert.IsTrue(false);
            }
            catch (Exception e)
            {
                Assert.IsTrue(e is IO.FileNotFoundException);
                Assert.IsTrue(true);
            }
        }