Exemplo n.º 1
0
        private async Task <bool> VerifyFXPTransferAsync(string sourcePath, FtpClient fxpDestinationClient, string remotePath, CancellationToken token = default(CancellationToken))
        {
            // verify args
            if (sourcePath.IsBlank())
            {
                throw new ArgumentException("Required parameter is null or blank.", nameof(sourcePath));
            }

            if (remotePath.IsBlank())
            {
                throw new ArgumentException("Required parameter is null or blank.", nameof(remotePath));
            }

            if (fxpDestinationClient is null)
            {
                throw new ArgumentNullException(nameof(fxpDestinationClient), "Destination FXP FtpClient cannot be null!");
            }

            // check if any algorithm is supported by both servers
            var algorithm = GetFirstMutualChecksum(fxpDestinationClient);

            if (algorithm != FtpHashAlgorithm.NONE)
            {
                // get the hashes of both files using the same mutual algorithm

                FtpHash sourceHash = await GetChecksumAsync(sourcePath, algorithm, token);

                if (!sourceHash.IsValid)
                {
                    return(false);
                }

                FtpHash destinationHash = await fxpDestinationClient.GetChecksumAsync(remotePath, algorithm, token);

                if (!destinationHash.IsValid)
                {
                    return(false);
                }

                return(sourceHash.Value == destinationHash.Value);
            }
            else
            {
                LogLine(FtpTraceLevel.Info, "Source and Destination servers do not support any common hashing algorithm");
            }

            // since not supported return true to ignore validation
            return(true);
        }
Exemplo n.º 2
0
        private async Task <bool> VerifyFXPTransferAsync(string sourcePath, FtpClient fxpDestinationClient, string remotePath, CancellationToken token = default(CancellationToken))
        {
            // verify args
            if (sourcePath.IsBlank())
            {
                throw new ArgumentException("Required parameter is null or blank.", "localPath");
            }

            if (remotePath.IsBlank())
            {
                throw new ArgumentException("Required parameter is null or blank.", "remotePath");
            }

            if (fxpDestinationClient is null)
            {
                throw new ArgumentNullException("Destination FXP FtpClient cannot be null!", "fxpDestinationClient");
            }

            if ((HasFeature(FtpCapability.HASH) && fxpDestinationClient.HasFeature(FtpCapability.HASH)) || (HasFeature(FtpCapability.MD5) && fxpDestinationClient.HasFeature(FtpCapability.MD5)) ||
                (HasFeature(FtpCapability.XMD5) && fxpDestinationClient.HasFeature(FtpCapability.XMD5)) || (HasFeature(FtpCapability.XCRC) && fxpDestinationClient.HasFeature(FtpCapability.XCRC)) ||
                (HasFeature(FtpCapability.XSHA1) && fxpDestinationClient.HasFeature(FtpCapability.XSHA1)) || (HasFeature(FtpCapability.XSHA256) & fxpDestinationClient.HasFeature(FtpCapability.XSHA256)) ||
                (HasFeature(FtpCapability.XSHA512) && fxpDestinationClient.HasFeature(FtpCapability.XSHA512)))
            {
                FtpHash sourceHash = await GetChecksumAsync(sourcePath, token);

                if (!sourceHash.IsValid)
                {
                    return(false);
                }


                FtpHash destinationHash = await fxpDestinationClient.GetChecksumAsync(remotePath, token);

                if (!destinationHash.IsValid)
                {
                    return(false);
                }

                return(sourceHash.Value == destinationHash.Value);
            }
            else
            {
                LogLine(FtpTraceLevel.Info, "Source and Destination does not support the same hash algorythm");
            }

            //Not supported return true to ignore validation
            return(true);
        }