Пример #1
0
        public void TestUserReportedError2()
        {
            // clean up anything that may have been left over from previous tests
            FtpsClient ftp1 = new FtpsClient(FTP_HOST, FTP_STD_PORT, FtpsSecurityProtocol.None);

            ftp1.NetworkProtocol = NETWORK_PROTOCOL;
            ftp1.Open(FTP_USER, FTP_PASS);

            try
            {
                ftp1.ChangeDirectory("test dir");
            }
            catch
            {
            }
            try
            {
                ftp1.DeleteFile("testfile.txt");
            }
            catch
            {
            }

            try
            {
                ftp1.ChangeDirectory("\\");
            }
            catch
            {
            }

            try
            {
                ftp1.DeleteDirectory("test dir");
            }
            catch
            {
            }


            FtpsClient ftp = new FtpsClient(FTP_HOST, FTP_STD_PORT, FtpsSecurityProtocol.Tls12Explicit);

            ftp.NetworkProtocol = NETWORK_PROTOCOL;
            ftp.AlwaysAcceptServerCertificate = true;
            ftp.Open(FTP_USER, FTP_PASS);
            ftp.MakeDirectory("test dir");
            ftp.ChangeDirectory("test dir");
            ftp.PutFile(GetMemoryStreamRandom(100), "testfile.txt", FileAction.Create);
            FtpsItemCollection col = ftp.GetDirList();

            ftp.Close();

            Assert.IsTrue(col.Count == 1);
        }
Пример #2
0
        public void TestUserReportedError2()
        {
            FtpsClient ftp = new FtpsClient(FTP_HOST, FTP_STD_PORT, FtpsSecurityProtocol.Tls1Explicit);

            ftp.NetworkProtocol = NETWORK_PROTOCOL;
            ftp.AlwaysAcceptServerCertificate = true;
            ftp.Open(FTP_USER, FTP_PASS);
            ftp.MakeDirectory("test dir");
            ftp.ChangeDirectory("test dir");
            ftp.PutFile(GetMemoryStreamRandom(100), "testfile.txt", FileAction.Create);
            FtpsItemCollection col = ftp.GetDirList();

            ftp.DeleteFile("testfile.txt");
            ftp.ChangeDirectory("\\");
            ftp.DeleteDirectory("test dir");
            ftp.Close();

            Assert.IsTrue(col.Count == 1);
        }
Пример #3
0
        public void TestGetDirList(string host, int port, FtpsSecurityProtocol protocol,
                                   string user, string pwd, string server)
        {
            using (FtpsClient c = new FtpsClient(host, port, protocol))
            {
                c.AlwaysAcceptServerCertificate = true;
                c.Open(user, pwd);
                Assert.IsTrue(c.IsConnected);
                FtpsItemCollection lst = c.GetDirList();

                Debug.WriteLine("===================================================");
                Debug.WriteLine("DIRECTORY DUMP");
                Debug.WriteLine("===================================================");
                foreach (FtpsItem item in lst)
                {
                    Debug.WriteLine(item.RawText);
                    Debug.WriteLine(item.ToString());
                }
                Debug.WriteLine("===================================================");
            }
        }
 /// <summary>
 ///  Initializes a new instance of the GetDirAsyncCompletedEventArgs class.
 /// </summary>
 /// <param name="error">Any error that occurred during the asynchronous operation.</param>
 /// <param name="canceled">A value indicating whether the asynchronous operation was canceled.</param>
 /// <param name="directoryListing">A FtpItemCollection containing the directory listing.</param>
 public GetDirListDeepAsyncCompletedEventArgs(Exception error, bool canceled, FtpsItemCollection directoryListing)
     : base(error, canceled, null)
 {
     _directoryListing = directoryListing;
 }
Пример #5
0
        private void ParseDirListDeep(string path, FtpsItemCollection deepCol)
        {
            FtpsItemCollection list = GetDirList(path);
            deepCol.Merge(list);

            foreach (FtpsItem item in list)
            {
                // if the this call is being completed asynchronously and the user requests a cancellation
                // then stop processing the items and return
                if (base.AsyncWorker != null && base.AsyncWorker.CancellationPending)
                    return;

                // if the item is of type Directory then parse the directory list recursively
                if (item.ItemType == FtpItemType.Directory)
                    ParseDirListDeep(item.FullPath, deepCol);
            }
        }
Пример #6
0
 /// <summary>
 /// Deeply retrieves a list of all files and all sub directories from a specified path on the remote FTP 
 /// server using the LIST command. 
 /// </summary>
 /// <param name="path">The path to a directory on the remote FTP server.</param>
 /// <returns>FtpFileCollection collection object.</returns>
 /// <remarks>
 /// This method returns a FtpFileCollection object containing a collection of 
 /// FtpItem objects.
 /// Note that some FTP servers will not accept a full path.  On those systems you must navigate to
 /// the parent directory you wish to get the directory list using with the ChangeDirectory() or ChangeDirectoryMultiPath()
 /// method.
 /// </remarks>
 /// <seealso cref="GetDirList()"/>
 /// <seealso cref="GetDirList(string)"/>
 /// <seealso cref="GetDirListAsText()"/>
 /// <seealso cref="GetDirListAsText(string)"/>
 /// <seealso cref="GetDirListAsync()"/>
 /// <seealso cref="GetDirListAsync(string)"/>
 /// <seealso cref="GetDirListDeepAsync(string)"/>
 /// <seealso cref="GetNameList()"/>
 /// <seealso cref="GetNameList(string)"/>
 public FtpsItemCollection GetDirListDeep(string path)
 {
     if (path == null)
         throw new ArgumentNullException("path");
     
     FtpsItemCollection deepCol = new FtpsItemCollection();
     ParseDirListDeep(path, deepCol);
     return deepCol;
 }