예제 #1
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);
                }
            }
        }
예제 #2
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);
        }
예제 #3
0
        public void TestUserReportedError1()
        {
            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.PutFile(GetMemoryStreamRandom(100), "testfile.txt", FileAction.Create);
            MemoryStream fout = new MemoryStream();

            ftp.GetFile("testfile.txt", fout, false);
            ftp.DeleteFile("testfile.txt");
            ftp.Close();
        }
예제 #4
0
        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);
            }
        }
예제 #5
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);
                }
            }
        }
예제 #6
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);
                }
            }
        }
예제 #7
0
        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);
                }
            }
        }
예제 #8
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);
        }
예제 #9
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);
                }
            }
        }
예제 #10
0
 private static void DoDeleteFile(FtpsClient client)
 {
     client.DeleteFile(NormalizeRemotePath(_commandArguments[0]));
 }