Esempio n. 1
0
        //[Fact]
        public async Task TestHashAsync()
        {
            using (FtpClient cl = NewFtpClient())
            {
                await cl.ConnectAsync();

                FtpTrace.WriteLine("Supported HASH algorithms: " + cl.HashAlgorithms);
                FtpTrace.WriteLine("Current HASH algorithm: " + await cl.GetHashAlgorithmAsync());

                foreach (FtpHashAlgorithm alg in Enum.GetValues(typeof(FtpHashAlgorithm)))
                {
                    if (alg != FtpHashAlgorithm.NONE && cl.HashAlgorithms.HasFlag(alg))
                    {
                        FtpHash hash = null;

                        await cl.SetHashAlgorithmAsync(alg);

                        hash = await cl.GetHashAsync("LICENSE.TXT");

                        if (hash.IsValid)
                        {
                            Debug.Assert(hash.Verify(@"C:\FTPTEST\LICENSE.TXT"), "The computed hash didn't match or the hash object was invalid!");
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        static void TestHash()
        {
            using (FtpClient cl = new FtpClient()) {
                cl.Credentials = new NetworkCredential(m_user, m_pass);
                cl.Host        = m_host;
                cl.Connect();

                Console.WriteLine("Supported HASH algorithms: {0}", cl.HashAlgorithms);
                Console.WriteLine("Current HASH algorithm: {0}", cl.GetHashAlgorithm());

                foreach (FtpHashAlgorithm alg in Enum.GetValues(typeof(FtpHashAlgorithm)))
                {
                    if (alg != FtpHashAlgorithm.NONE && cl.HashAlgorithms.HasFlag(alg))
                    {
                        FtpHash hash = null;

                        cl.SetHashAlgorithm(alg);
                        hash = cl.GetHash("LICENSE.TXT");

                        if (hash.IsValid)
                        {
                            Debug.Assert(hash.Verify(@"C:\FTPTEST\LICENSE.TXT"), "The computed hash didn't match or the hash object was invalid!");
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        public static void GetChceksumExample()
        {
            FtpHash hash = null;

            using (FtpClient cl = new FtpClient()) {
                cl.Credentials = new NetworkCredential("user", "pass");
                cl.Host        = "some.ftpserver.on.the.internet.com";

                hash = cl.GetChecksum("/path/to/remote/file");
                // Make sure it returned a, to the best of our knowledge, valid
                // hash object. The commands for retrieving checksums are
                // non-standard extensions to the protocol so we have to
                // presume that the response was in a format understood by
                // FluentFTP and parsed correctly.
                //
                // In addition, there is no built-in support for verifying
                // CRC hashes. You will need to write you own or use a
                // third-party solution.
                if (hash.IsValid && hash.Algorithm != FtpHashAlgorithm.CRC)
                {
                    if (hash.Verify("/some/local/file"))
                    {
                        Console.WriteLine("The checksum's match!");
                    }
                }
            }
        }
Esempio n. 4
0
        public static void GetChecksum()
        {
            using (var conn = new FtpClient("127.0.0.1", "ftptest", "ftptest")) {
                conn.Connect();

                FtpHash hash = conn.GetChecksum("/path/to/remote/file");

                // Make sure it returned a, to the best of our knowledge, valid
                // hash object. The commands for retrieving checksums are
                // non-standard extensions to the protocol so we have to
                // presume that the response was in a format understood by
                // FluentFTP and parsed correctly.
                //
                // In addition, there is no built-in support for verifying
                // CRC hashes. You will need to write you own or use a
                // third-party solution.
                if (hash.IsValid && hash.Algorithm != FtpHashAlgorithm.CRC)
                {
                    if (hash.Verify("/some/local/file"))
                    {
                        Console.WriteLine("The checksum's match!");
                    }
                }
            }
        }
Esempio n. 5
0
        //-----------------------------------------------------------------------------------------
        // NOTE! GetChecksum automatically uses the first available hash algorithm on the server,
        //		 and it should be used as far as possible instead of GetHash, GetMD5, GetSHA256...
        //-----------------------------------------------------------------------------------------

        public static void GetChecksum()
        {
            using (var conn = new FtpClient("127.0.0.1", "ftptest", "ftptest")) {
                conn.Connect();

                // Get a hash checksum for the file
                FtpHash hash = conn.GetChecksum("/path/to/remote/file");

                // Make sure it returned a valid hash object
                if (hash.IsValid)
                {
                    if (hash.Verify("/some/local/file"))
                    {
                        Console.WriteLine("The checksum's match!");
                    }
                }
            }
        }
Esempio n. 6
0
        public static async Task GetChecksumAsync()
        {
            var token = new CancellationToken();

            using (var conn = new FtpClient("127.0.0.1", "ftptest", "ftptest")) {
                await conn.ConnectAsync(token);

                // Get a hash checksum for the file
                FtpHash hash = await conn.GetChecksumAsync("/path/to/remote/file", token);

                // Make sure it returned a valid hash object
                if (hash.IsValid)
                {
                    if (hash.Verify("/some/local/file"))
                    {
                        Console.WriteLine("The checksum's match!");
                    }
                }
            }
        }