Exemple #1
0
        public FtpClientIntegrationTest()
        {
            _ftpUriConfigDetails = new UriBuilder(ConfigurationManager.AppSettings[uriConfigKey]);

            _ftpFileContainer   = FTPFile.UnityContainerFactory();
            _ftpFolderContainer = FTPFolder.UnityContainerFactory();
        }
Exemple #2
0
        public void FilenameContainsWhitespace()
        {
            var ftpFile = new FTPFile(string.Format(@"{0}/Copy of Test.xml", _ftpUriConfigDetails.Uri.AbsoluteUri));

            ftpFile.PassiveMode = true;
            Assert.IsTrue(ftpFile.PassiveMode);
        }
Exemple #3
0
        public void FTPFileConstructors()
        {
            var ftpFile1 = new FTPFile(_ftpUriConfigDetails.Uri.AbsoluteUri, _ftpUriConfigDetails.UserName, _ftpUriConfigDetails.Password);

            Assert.IsTrue(!string.IsNullOrEmpty(ftpFile1.GetParentDirectory()));
            Assert.IsTrue(ftpFile1 != null);

            var ftpFile2 = new FTPFile(_ftpUriConfigDetails.Uri.AbsoluteUri, _ftpUriConfigDetails.UserName, _ftpUriConfigDetails.Password);

            Assert.IsTrue(!string.IsNullOrEmpty(ftpFile2.GetParentDirectory()));
            Assert.IsTrue(ftpFile2 != null);
        }
Exemple #4
0
        override public void Initialize(string uri)
        {
            base.InitializeUri(uri);

            _ftpFolder = new FTPFolder(_ftpuri.FormatFtpUri(_username, _password))
            {
                PassiveMode = false, IsBubbleUpException = _isDownload
            };

            var strFolderList = new List <string>();
            var strFileList   = new List <string>();

            _ftpFolder.ListDirectory(out strFolderList, out strFileList);

            strFileList.ForEach(fileName =>
            {
                var ftpFile = new FTPFile(_ftpuri.FormatFtpUri(_username, _password, fileName))
                {
                    PassiveMode = false, IsBubbleUpException = _isDownload
                };
                if (null != TimeOut)
                {
                    ftpFile.TimeOut = TimeOut;
                }

                _ftpFileList.Add(ftpFile);
                if (_isDownload)
                {
                    ftpFile.DownloadFile(Path.Combine(LocalFolderRoot, fileName));
                }
            });

            strFolderList.ForEach(subfolder =>
            {
                var subUri      = string.Format(@"{0}/{1}", _ftpuri, subfolder);
                var localFolder = Path.Combine(_localFolderRoot, subfolder);
                var ftpTreeNode = new FTPTreeNode(subUri,
                                                  _username,
                                                  _password,
                                                  localFolder,
                                                  IsDownload)
                {
                    PassiveMode = false, TimeOut = TimeOut
                };
                _ftpTreeNodeList.Add(ftpTreeNode);
                ftpTreeNode.Initialize(ComposeInitialUriString(subUri, _username, _password));
            });
        }
Exemple #5
0
        public bool DeleteSubFolder(string folderName)
        {
            bool success = false;

            if (string.IsNullOrEmpty(folderName))
            {
                throw new ArgumentException("The folder name is invalid for deleting subfolder");
            }
            var folderList = new List <string>();
            var fileList   = new List <string>();

            string message = string.Empty;

            if (IsSubFoderExisted(folderName))
            {
                ListDirectory(out folderList, out fileList, folderName);

                if (folderList.Count > 0)
                {
                    throw new ApplicationException(string.Format(@"The folder <{0}> contains sub folders and can't be deleted.", folderName));
                }

                fileList.ForEach(file =>
                {
                    var uri = string.Format(@"{0}{1}{2}{1}{3}",
                                            FtpUri,
                                            PathSeparator,
                                            folderName,
                                            file);
                    var ftpFile = new FTPFile(uri);
                    ftpFile.DeleteFile();
                });

                var request = CreateRequest(WebRequestMethods.Ftp.RemoveDirectory, folderName);
                using (var response = request.GetResponse())
                {
                    success = true;
                    response.Close();
                }
            }
            else
            {
                message = @"Folder is not existed";
            }

            return(success);
        }
Exemple #6
0
        public void CompareTest()
        {
            var tempUri1 = string.Format(@"{0}/{1}_1", _ftpUriConfigDetails.Uri.AbsoluteUri, TempsubFolderName);
            var tempUri2 = string.Format(@"{0}/{1}_2", _ftpUriConfigDetails.Uri.AbsoluteUri, TempsubFolderName);
            var ftpFile1 = new FTPFile();
            var ftpFile2 = new FTPFile();

            ftpFile1.Initialize(tempUri1);
            ftpFile2.Initialize(tempUri1);
            Assert.AreEqual(1, ftpFile1.CompareTo(ftpFile2));
            ftpFile2.Initialize(tempUri2);
            Assert.AreEqual(0, ftpFile1.CompareTo(ftpFile2));
            var ftpTFolder1 = new FTPFolder();
            var ftpTFolder2 = new FTPFolder();

            ftpTFolder1.Initialize(tempUri1);
            ftpTFolder2.Initialize(tempUri1);
            Assert.AreEqual(1, ftpTFolder1.CompareTo(ftpTFolder2));
            ftpTFolder2.Initialize(tempUri2);
            Assert.AreEqual(0, ftpTFolder1.CompareTo(ftpTFolder2));
        }
Exemple #7
0
        public void DeleteFilNotExists()
        {
            var ftpFile = new FTPFile(string.Format(@"{0}/Foo.txt", _ftpUriConfigDetails.Uri.AbsoluteUri));

            Assert.IsFalse(ftpFile.DeleteFile());
        }
Exemple #8
0
 public void InvalidUri()
 {
     var ftpFile = new FTPFile(@"ftp:/");
 }