Calculating checksum match after transfer

Advertisement

carenrose
Joined:
Posts:
1

Calculating checksum match after transfer

I'm attempting to get files from the remote server, then check that the checksum of the remote and local file match, either before deleting the remote file or just to ensure it was transferred properly.

using (var session = new Session())
{
    session.FileTransferred += Session_FileDownloaded;
    session.Open(new SessionOptions { ... });
 
    var files = session.EnumerateRemoteFiles(path, "", EnumerationOptions.None);
    foreach (var file in files)
    {
        session.GetFiles(file.FullName, Path.Combine(dest, file.Name));
    }
}

private static SHA1 sha1 = SHA1.Create();
 
private static void Session_FileDownloaded(object sender, TransferEventArgs e)
{
    var session = sender as Session;
    if (session != null)
    {
        var remote = e.FileName;
        var local  = e.Destination;
 
        var remoteChkSum = 
            BitConverter.ToString(session.CalculateFileChecksum("sha-1", remote));
        var localChkSum  = 
            BitConverter.ToString(sha1.ComputeHash(File.OpenRead(local)));
    }
}

It's throwing an InvalidOperationException on this line: BitConverter.ToString(session.CalculateFileChecksum("sha-1", remote)), with the message "Recursive calls not allowed".

What is the correct way to do this?

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum