Post a reply

Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)


Topic review


Re: Calculating checksum match after transfer

Do your checksum test after GetFiles finishes. Not within FileTransferred event.

Though note what few servers actually support checksum calculation.

Also, you should call session.Check.

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  =

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?