public void TestUserReportedError2(string host, int port, FtpsSecurityProtocol protocol,
     string user, string pwd, string server)
 {
     FtpsClient ftp = new FtpsClient("127.0.0.1", port, protocol);
     ftp.AlwaysAcceptServerCertificate = true;
     ftp.Open("test", "test");
     ftp.GetFile("luna.h", "luna1-2.h", FileAction.Create);
     ftp.Close();
 }
 public void TestOpenUsing(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);
     }
 }
        public void TestUserReportedError2(string host, int port, FtpsSecurityProtocol protocol,
                                           string user, string pwd, string server)
        {
            FtpsClient ftp = new FtpsClient("127.0.0.1", port, protocol);

            ftp.AlwaysAcceptServerCertificate = true;
            ftp.Open("test", "test");
            ftp.GetFile("luna.h", "luna1-2.h", FileAction.Create);
            ftp.Close();
        }
Example #4
0
        public void TestPutFileResume(string host, int port, FtpsSecurityProtocol protocol,
                                      string user, string pwd, int fileSize)
        {
            using (FtpsClient c = new FtpsClient(host, port, protocol))
            {
                c.NetworkProtocol = NETWORK_PROTOCOL;
                c.AlwaysAcceptServerCertificate = true;
                c.Open(user, pwd);
                Assert.IsTrue(c.IsConnected);

                MemoryStream m1 = GetMemoryStreamRandom(fileSize);
                MemoryStream m2 = GetMemoryStreamRandom(fileSize);

                byte[] a = m1.ToArray();
                byte[] b = m2.ToArray();
                byte[] l = new byte[a.Length + b.Length];
                Array.Copy(a, l, a.Length);
                Array.Copy(b, 0, l, a.Length, b.Length);

                // m3 is m1 + m2
                MemoryStream m3 = new MemoryStream(l);

                string fname = GetGuidString();

                try
                {
                    c.PutFile(m1, fname, FileAction.Create);

                    Assert.IsTrue(c.Exists(fname));

                    MemoryStream o1 = new MemoryStream();
                    c.GetFile(fname, o1, false);
                    o1.Position = 0;

                    //compare bytes to verify
                    Assert.IsTrue(Compare(m1, o1));

                    // put m3 as a resume file
                    c.PutFile(m3, fname, FileAction.Resume);

                    Assert.IsTrue(c.Exists(fname));

                    MemoryStream o2 = new MemoryStream();
                    c.GetFile(fname, o2, false);
                    o1.Position = 0;

                    //compare bytes to verify
                    Assert.IsTrue(Compare(m3, o2));
                }
                finally
                {
                    c.DeleteFile(fname);
                }
            }
        }
 public void TestAbort(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);
         c.Abort();
     }
 }
Example #6
0
        public void TestOpen(string host, int port, FtpsSecurityProtocol protocol,
                             string user, string pwd)
        {
            FtpsClient c = new FtpsClient(host, port, protocol);

            c.NetworkProtocol = NETWORK_PROTOCOL;
            c.AlwaysAcceptServerCertificate = true;
            c.Open(user, pwd);
            Assert.IsTrue(c.IsConnected);
            c.Close();
        }
Example #7
0
 public void TestAllocateStorage(string host, int port, FtpsSecurityProtocol protocol,
                                 string user, string pwd)
 {
     using (FtpsClient c = new FtpsClient(host, port, protocol))
     {
         c.NetworkProtocol = NETWORK_PROTOCOL;
         c.AlwaysAcceptServerCertificate = true;
         c.Open(user, pwd);
         Assert.IsTrue(c.IsConnected);
         c.AllocateStorage(DEFAULT_FILE_SIZE * 16);
     }
 }
Example #8
0
 public void TestUtf8On(string host, int port, FtpsSecurityProtocol protocol,
                        string user, string pwd)
 {
     using (FtpsClient c = new FtpsClient(host, port, protocol))
     {
         c.NetworkProtocol = NETWORK_PROTOCOL;
         c.AlwaysAcceptServerCertificate = true;
         c.Open(user, pwd);
         Assert.IsTrue(c.IsConnected);
         c.SetUtf8On();
         //Assert.IsTrue(c.Encoding == Encoding.UTF8);
     }
 }
 public void TestGetSystemType(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);
         string r = c.GetSystemType();
         Assert.IsNotNullOrEmpty(r);
         Debug.WriteLine("RESULT: " + r);
     }
 }
Example #10
0
 public void TestQuote(string host, int port, FtpsSecurityProtocol protocol,
                       string user, string pwd)
 {
     using (FtpsClient c = new FtpsClient(host, port, protocol))
     {
         c.NetworkProtocol = NETWORK_PROTOCOL;
         c.AlwaysAcceptServerCertificate = true;
         c.Open(user, pwd);
         Assert.IsTrue(c.IsConnected);
         string result = c.Quote("HELP");
         Assert.IsNotNull(result);
         Assert.IsNotEmpty(result);
     }
 }
        public void TestPutFileUnique(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);

                byte[]       bytes = new byte[1024];
                MemoryStream m     = new MemoryStream(bytes);
                string       fname = c.PutFileUnique(m);
                c.DeleteFile(fname);
            }
        }
Example #12
0
 public void TestGetSystemType(string host, int port, FtpsSecurityProtocol protocol,
                               string user, string pwd)
 {
     using (FtpsClient c = new FtpsClient(host, port, protocol))
     {
         c.NetworkProtocol = NETWORK_PROTOCOL;
         c.AlwaysAcceptServerCertificate = true;
         c.Open(user, pwd);
         Assert.IsTrue(c.IsConnected);
         string r = c.GetSystemType();
         Assert.IsNotNull(r);
         Assert.IsNotEmpty(r);
         Console.WriteLine("RESULT: " + r);
     }
 }
 public void TestRepeatedOpen(string host, int port, FtpsSecurityProtocol protocol,
                              string user, string pwd, string server, int connections)
 {
     for (int i = 0; i < connections; i++)
     {
         using (FtpsClient c = new FtpsClient(host, port, protocol))
         {
             Debug.WriteLine("********** START **********");
             c.AlwaysAcceptServerCertificate = true;
             c.Open(user, pwd);
             Assert.IsTrue(c.IsConnected);
             Debug.WriteLine("********** PASSED **********");
         }
     }
 }
Example #14
0
        public void TestChangeDirectory(string host, int port, FtpsSecurityProtocol protocol,
                                        string user, string pwd)
        {
            using (FtpsClient c = new FtpsClient(host, port, protocol))
            {
                c.NetworkProtocol = NETWORK_PROTOCOL;
                c.AlwaysAcceptServerCertificate = true;
                c.Open(user, pwd);
                Assert.IsTrue(c.IsConnected);
                string dir1 = Guid.NewGuid().ToString();
                string dir2 = Guid.NewGuid().ToString();
                string dir3 = Guid.NewGuid().ToString();
                string dir4 = Guid.NewGuid().ToString();

                // create the directories and change into them
                c.MakeDirectory(dir1);
                c.ChangeDirectory(dir1);
                c.MakeDirectory(dir2);
                c.ChangeDirectory(dir2);
                c.MakeDirectory(dir3);
                c.ChangeDirectory(dir3);
                c.MakeDirectory(dir4);

                c.ChangeDirectoryUp();
                c.ChangeDirectoryUp();
                c.ChangeDirectoryUp();
                c.ChangeDirectoryUp();

                // try changing directory using a full path which does
                // not work for all FTP servers
                c.ChangeDirectory(String.Format("{0}/{1}/{2}/{3}", dir1, dir2, dir3, dir4));
                c.ChangeDirectory("//");

                // try changing directory using multipath command which should work
                // for all FTP servers
                c.ChangeDirectoryMultiPath(String.Format("{0}/{1}/{2}/{3}", dir1, dir2, dir3, dir4));
                c.ChangeDirectoryUp();

                // delete the temporary directories
                c.DeleteDirectory(dir4);
                c.ChangeDirectoryUp();
                c.DeleteDirectory(dir3);
                c.ChangeDirectoryUp();
                c.DeleteDirectory(dir2);
                c.ChangeDirectoryUp();
                c.DeleteDirectory(dir1);
            }
        }
Example #15
0
        public void TestPutFileCreateNew(string host, int port, FtpsSecurityProtocol protocol,
                                         string user, string pwd, int fileSize)
        {
            using (FtpsClient c = new FtpsClient(host, port, protocol))
            {
                c.NetworkProtocol = NETWORK_PROTOCOL;
                c.AlwaysAcceptServerCertificate = true;
                c.Open(user, pwd);
                Assert.IsTrue(c.IsConnected);

                MemoryStream m1    = GetMemoryStreamRandom(fileSize);
                string       fname = GetGuidString();
                bool         fail  = false;

                try
                {
                    c.PutFile(m1, fname, FileAction.Create);

                    Assert.IsTrue(c.Exists(fname));

                    MemoryStream o1 = new MemoryStream();
                    c.GetFile(fname, o1, false);
                    o1.Position = 0;

                    //compare bytes to verify
                    Assert.IsTrue(Compare(m1, o1));

                    c.PutFile(m1, fname, FileAction.Create);

                    try
                    {
                        // put a second time which should cause an exception to be thrown
                        // since there is an existing file already on the server
                        c.PutFile(m1, fname, FileAction.CreateNew);
                    }
                    catch (FtpsDataTransferException)
                    {
                        fail = true;
                    }

                    Assert.IsTrue(fail);
                }
                finally
                {
                    c.DeleteFile(fname);
                }
            }
        }
Example #16
0
        public void TestGetFile(string host, int port, FtpsSecurityProtocol protocol, string user, string pwd)
        {
            using (FtpsClient c = new FtpsClient(host, port, protocol))
            {
                c.NetworkProtocol = NETWORK_PROTOCOL;
                c.AlwaysAcceptServerCertificate = true;
                c.TcpBufferSize = 80000;
                c.Open(user, pwd);

                Assert.IsTrue(c.IsConnected);

                MemoryStream msfile = new MemoryStream();
                c.GetFile("/gcrypt/gnupg/index.html", msfile, false);

                Assert.IsTrue(msfile.Length != 0);
            }
        }
Example #17
0
        public void TestPutFileCreate(string host, int port, FtpsSecurityProtocol protocol,
                                      string user, string pwd, int fileSize)
        {
            using (FtpsClient c = new FtpsClient(host, port, protocol))
            {
                c.NetworkProtocol = NETWORK_PROTOCOL;
                c.AlwaysAcceptServerCertificate = true;
                c.NetworkProtocol = NetworkVersion.IPv6;
                c.Open(user, pwd);
                Assert.IsTrue(c.IsConnected);

                MemoryStream m1 = GetMemoryStreamRandom(fileSize);

                string fname = GetGuidString();

                try
                {
                    c.PutFile(m1, fname, FileAction.Create);

                    Assert.IsTrue(c.Exists(fname));

                    MemoryStream o1 = new MemoryStream();
                    c.GetFile(fname, o1, false);
                    o1.Position = 0;

                    // compare bytes to verify
                    Assert.IsTrue(Compare(m1, o1));

                    // put a second file which should overwrite the first file
                    c.PutFile(m1, fname, FileAction.Create);

                    Assert.IsTrue(c.Exists(fname));

                    MemoryStream o2 = new MemoryStream();
                    c.GetFile(fname, o2, false);
                    o1.Position = 0;

                    // compare bytes to verify
                    Assert.IsTrue(Compare(m1, o2));
                }
                finally
                {
                    c.DeleteFile(fname);
                }
            }
        }
        public void TestPutFileCreateOrAppend(string host, int port, FtpsSecurityProtocol protocol,
                                              string user, string pwd, string server, int fileSize)
        {
            using (FtpsClient c = new FtpsClient(host, port, protocol))
            {
                c.AlwaysAcceptServerCertificate = true;
                c.Open(user, pwd);
                Assert.IsTrue(c.IsConnected);

                MemoryStream m1    = GetRandom(fileSize);
                MemoryStream m2    = GetRandom(fileSize);
                string       fname = GetGuidString();

                try
                {
                    c.PutFile(m1, fname, FileAction.Create);

                    Assert.IsTrue(c.Exists(fname));

                    MemoryStream o1 = new MemoryStream();
                    c.GetFile(fname, o1, false);
                    o1.Position = 0;

                    //compare bytes to verify
                    Assert.IsTrue(Compare(m1, o1));

                    // put a second file which should append to the first file
                    c.PutFile(m2, fname, FileAction.CreateOrAppend);

                    Assert.IsTrue(c.Exists(fname));

                    MemoryStream o2 = new MemoryStream();
                    c.GetFile(fname, o2, false);
                    o1.Position = 0;

                    //compare bytes to verify m1 and m2 were appended together
                    Assert.IsTrue(Compare(m1, m2, o2));
                }
                finally
                {
                    c.DeleteFile(fname);
                }
            }
        }
Example #19
0
 public void TestGetFileInfo(string host, int port, FtpsSecurityProtocol protocol,
     string user, string pwd, ListingMethod method)
 {
     using (FtpsClient c = new FtpsClient(host, port, protocol))
     {
         Debug.WriteLine("********** BEGINNING **********");
         c.AlwaysAcceptServerCertificate = true;
         c.DirListingMethod = method;
         c.Open(user, pwd);
         Assert.IsTrue(c.IsConnected);
         // get information about the root directory
         FtpsItem m = c.GetFileInfo(".");
         if (m is FtpsMlsxItem)
             Debug.Write(((FtpsMlsxItem)m).ToString());
         else
             Debug.Write(m.ToString());
         Debug.WriteLine("********** ENDING **********");
     }
 }
        public void TestMultiOpen(string host, int port, FtpsSecurityProtocol protocol,
                                  string user, string pwd, string server, int connections)
        {
            FtpsClient[] lst = new FtpsClient[connections];

            for (int i = 0; i < lst.Length; i++)
            {
                FtpsClient c = new FtpsClient(host, port, protocol);
                c.AlwaysAcceptServerCertificate = true;
                c.Open(user, pwd);
                Assert.IsTrue(c.IsConnected);
                lst[i] = c;
            }

            for (int i = 0; i < lst.Length; i++)
            {
                lst[i].Close();
            }
        }
        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("===================================================");
            }
        }
Example #22
0
        public void TestPutFileResumeCreate(string host, int port, FtpsSecurityProtocol protocol,
                                            string user, string pwd, int fileSize)
        {
            using (FtpsClient c = new FtpsClient(host, port, protocol))
            {
                c.NetworkProtocol = NETWORK_PROTOCOL;
                c.AlwaysAcceptServerCertificate = true;
                c.Open(user, pwd);
                Assert.IsTrue(c.IsConnected);

                MemoryStream m1    = GetMemoryStreamRandom(fileSize);
                string       fname = GetGuidString();

                try
                {
                    // attempt to put a new file on the system which will result in
                    // no resume action but rather a create action to be performed
                    c.PutFile(m1, fname, FileAction.ResumeOrCreate);

                    Assert.IsTrue(c.Exists(fname));

                    MemoryStream o1 = new MemoryStream();
                    c.GetFile(fname, o1, false);
                    o1.Position = 0;

                    //compare bytes to verify
                    Assert.IsTrue(Compare(m1, o1));

                    // try to resume the file after it has already been transmitted
                    // this should result in a test on the file lengths and no action
                    // being performed by the FTP client
                    c.PutFile(m1, fname, FileAction.Resume);
                }
                finally
                {
                    c.DeleteFile(fname);
                }
            }
        }
Example #23
0
 public void TestGetFileInfo(string host, int port, FtpsSecurityProtocol protocol,
                             string user, string pwd, ListingMethod method)
 {
     using (FtpsClient c = new FtpsClient(host, port, protocol))
     {
         Debug.WriteLine("********** BEGINNING **********");
         c.AlwaysAcceptServerCertificate = true;
         c.DirListingMethod = method;
         c.Open(user, pwd);
         Assert.IsTrue(c.IsConnected);
         // get information about the root directory
         FtpsItem m = c.GetFileInfo(".");
         if (m is FtpsMlsxItem)
         {
             Debug.Write(((FtpsMlsxItem)m).ToString());
         }
         else
         {
             Debug.Write(m.ToString());
         }
         Debug.WriteLine("********** ENDING **********");
     }
 }
 public void TestGetSystemType(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);
         string r = c.GetSystemType();
         Assert.IsNotNullOrEmpty(r);
         Debug.WriteLine("RESULT: " + r);
     }
 }
        public void TestPutFileUnique(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);

                byte[] bytes = new byte[1024];
                MemoryStream m = new MemoryStream(bytes);
                string fname = c.PutFileUnique(m);
                c.DeleteFile(fname);
            }
        }
        public void TestPutFileCreateNew(string host, int port, FtpsSecurityProtocol protocol,
            string user, string pwd, string server, int fileSize)
        {
            using (FtpsClient c = new FtpsClient(host, port, protocol))
            {
                c.AlwaysAcceptServerCertificate = true;
                c.Open(user, pwd);
                Assert.IsTrue(c.IsConnected);

                MemoryStream m1 = GetRandom(fileSize);
                MemoryStream m2 = GetRandom(fileSize);
                string fname = GetGuidString();
                bool fail = false;

                try
                {
                    c.PutFile(m1, fname, FileAction.Create);

                    Assert.IsTrue(c.Exists(fname));

                    MemoryStream o1 = new MemoryStream();
                    c.GetFile(fname, o1, false);
                    o1.Position = 0;

                    //compare bytes to verify
                    Assert.IsTrue(Compare(m1, o1));

                    c.PutFile(m1, fname, FileAction.Create);

                    try
                    {
                        // put a second time which should cause an exception to be thrown
                        // since there is an existing file already on the server
                        c.PutFile(m1, fname, FileAction.CreateNew);
                    }
                    catch (FtpsDataTransferException)
                    {
                        fail = true;
                    }

                    Assert.IsTrue(fail);

                }
                finally
                {
                    c.DeleteFile(fname);
                }

            }
        }
        public void TestPutFileCreateOrAppend(string host, int port, FtpsSecurityProtocol protocol,
            string user, string pwd, string server, int fileSize)
        {
            using (FtpsClient c = new FtpsClient(host, port, protocol))
            {
                c.AlwaysAcceptServerCertificate = true;
                c.Open(user, pwd);
                Assert.IsTrue(c.IsConnected);

                MemoryStream m1 = GetRandom(fileSize);
                MemoryStream m2 = GetRandom(fileSize);
                string fname = GetGuidString();

                try
                {
                    c.PutFile(m1, fname, FileAction.Create);

                    Assert.IsTrue(c.Exists(fname));

                    MemoryStream o1 = new MemoryStream();
                    c.GetFile(fname, o1, false);
                    o1.Position = 0;

                    //compare bytes to verify
                    Assert.IsTrue(Compare(m1, o1));

                    // put a second file which should append to the first file
                    c.PutFile(m2, fname, FileAction.CreateOrAppend);

                    Assert.IsTrue(c.Exists(fname));

                    MemoryStream o2 = new MemoryStream();
                    c.GetFile(fname, o2, false);
                    o1.Position = 0;

                    //compare bytes to verify m1 and m2 were appended together
                    Assert.IsTrue(Compare(m1, m2, o2));
                }
                finally
                {
                    c.DeleteFile(fname);
                }

            }
        }
        public void TestMultiOpen(string host, int port, FtpsSecurityProtocol protocol,
            string user, string pwd, string server, int connections)
        {
            FtpsClient[] lst = new FtpsClient[connections];

            for(int i=0; i< lst.Length; i++)
            {
                FtpsClient c = new FtpsClient(host, port, protocol);
                c.AlwaysAcceptServerCertificate = true;
                c.Open(user, pwd);
                Assert.IsTrue(c.IsConnected);
                lst[i] = c;
            }

            for (int i = 0; i < lst.Length; i++)
            {
                lst[i].Close();
            }
            
        }
Example #29
0
        /// <summary>
        /// Initializes a new instance of the FtpNetworkAdapter class.
        /// </summary>
        /// <param name="host">Host the adapter is to communicate on.</param>
        /// <param name="port">Port number the adapter is to communicate on.</param>
        /// <param name="securityProtocol">Value indicating what secure security communications protocol should be used (if any).</param>
        internal FtpsBase(string host, int port, FtpsSecurityProtocol securityProtocol)
		{
			_host = host;
			_port = port;
            _securityProtocol = securityProtocol;
        }
Example #30
0
 /// <summary>
 /// Initializes a new instance of the FtpNetworkAdapter class.
 /// </summary>
 /// <param name="port">Port number the adapter is to communicate on.</param>
 /// <param name="securityProtocol">Value indicating what secure security communications protocol should be used (if any).</param>
 internal FtpsBase(int port, FtpsSecurityProtocol securityProtocol)
 {
     _port = port;
     _securityProtocol = securityProtocol;
 }
        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("===================================================");

            }
        }
        public void TestChangeDirectory(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);
                string dir1 = Guid.NewGuid().ToString();
                string dir2 = Guid.NewGuid().ToString();
                string dir3 = Guid.NewGuid().ToString();
                string dir4 = Guid.NewGuid().ToString();

                // create the directories and change into them
                c.MakeDirectory(dir1);
                c.ChangeDirectory(dir1);
                c.MakeDirectory(dir2);
                c.ChangeDirectory(dir2);
                c.MakeDirectory(dir3);
                c.ChangeDirectory(dir3);
                c.MakeDirectory(dir4);

                c.ChangeDirectoryUp();
                c.ChangeDirectoryUp();
                c.ChangeDirectoryUp();
                c.ChangeDirectoryUp();

                // try changing directory using a full path which does 
                // not work for all FTP servers
                c.ChangeDirectory(String.Format("{0}/{1}/{2}/{3}", dir1, dir2, dir3, dir4));
                c.ChangeDirectory("//");

                // try changing directory using multipath command which should work
                // for all FTP servers
                c.ChangeDirectoryMultiPath(String.Format("{0}/{1}/{2}/{3}", dir1, dir2, dir3, dir4));
                c.ChangeDirectoryUp();
  
                // delete the temporary directories
                c.DeleteDirectory(dir4);
                c.ChangeDirectoryUp();
                c.DeleteDirectory(dir3);
                c.ChangeDirectoryUp();
                c.DeleteDirectory(dir2);
                c.ChangeDirectoryUp();
                c.DeleteDirectory(dir1);
            }
        }
 public void TestRepeatedOpen(string host, int port, FtpsSecurityProtocol protocol,
     string user, string pwd, string server, int connections)
 {
     for (int i = 0; i < connections; i++)
     {
         using (FtpsClient c = new FtpsClient(host, port, protocol))
         {
             Debug.WriteLine("********** START **********");
             c.AlwaysAcceptServerCertificate = true;
             c.Open(user, pwd);
             Assert.IsTrue(c.IsConnected);
             Debug.WriteLine("********** PASSED **********");
         }
     }
 }
        public void TestPutFileResumeCreate(string host, int port, FtpsSecurityProtocol protocol,
            string user, string pwd, string server, int fileSize)
        {
            using (FtpsClient c = new FtpsClient(host, port, protocol))
            {
                c.AlwaysAcceptServerCertificate = true;
                c.Open(user, pwd);
                Assert.IsTrue(c.IsConnected);

                MemoryStream m1 = GetRandom(fileSize);
                MemoryStream m2 = GetRandom(fileSize);
                string fname = GetGuidString();

                try
                {
                    // attempt to put a new file on the system which will result in 
                    // no resume action but rather a create action to be performed
                    c.PutFile(m1, fname, FileAction.ResumeOrCreate);

                    Assert.IsTrue(c.Exists(fname));

                    MemoryStream o1 = new MemoryStream();
                    c.GetFile(fname, o1, false);
                    o1.Position = 0;

                    //compare bytes to verify
                    Assert.IsTrue(Compare(m1, o1));

                    // try to resume the file after it has already been transmitted
                    // this should result in a test on the file lengths and no action
                    // being performed by the FTP client
                    c.PutFile(m1, fname, FileAction.Resume);

                }
                finally
                {
                    c.DeleteFile(fname);
                }

            }
        }
Example #35
0
 /// <summary>
 /// Constructor method for FtpsClient.  
 /// </summary>
 /// <param name="host">String containing the host name or ip address of the remote FTP server.</param>
 /// <param name="port">Port number used to connect to the remote FTP server.</param>
 /// <param name="securityProtocol">Enumeration value indicating what security protocol (such as SSL) should be enabled for this connection.</param>
 /// <remarks>
 /// This method takes three parameters that specify 
 /// the host name (or ip address), port to connect to and what security protocol should be used when establishing the connection.
 /// </remarks>
 public FtpsClient(string host, int port, FtpsSecurityProtocol securityProtocol) : base(host, port, securityProtocol) 
 {  }
        public void TestPutFileResume(string host, int port, FtpsSecurityProtocol protocol,
            string user, string pwd, string server, int fileSize)
        {
            using (FtpsClient c = new FtpsClient(host, port, protocol))
            {
                c.AlwaysAcceptServerCertificate = true;
                c.Open(user, pwd);
                Assert.IsTrue(c.IsConnected);

                MemoryStream m1 = GetRandom(fileSize);
                MemoryStream m2 = GetRandom(fileSize);

                byte[] a = m1.ToArray();
                byte[] b = m2.ToArray();
                byte[] l = new byte[a.Length + b.Length];
                Array.Copy(a, l, a.Length);
                Array.Copy(b, 0, l, a.Length, b.Length);

                // m3 is m1 + m2
                MemoryStream m3 = new MemoryStream(l);

                string fname = GetGuidString();

                try
                {
                    c.PutFile(m1, fname, FileAction.Create);

                    Assert.IsTrue(c.Exists(fname));

                    MemoryStream o1 = new MemoryStream();
                    c.GetFile(fname, o1, false);
                    o1.Position = 0;

                    //compare bytes to verify
                    Assert.IsTrue(Compare(m1, o1));

                    // put m3 as a resume file
                    c.PutFile(m3, fname, FileAction.Resume);

                    Assert.IsTrue(c.Exists(fname));

                    MemoryStream o2 = new MemoryStream();
                    c.GetFile(fname, o2, false);
                    o1.Position = 0;

                    //compare bytes to verify
                    Assert.IsTrue(Compare(m3, o2));
                }
                finally
                {
                    c.DeleteFile(fname);
                }

            }
        }