Open
Description
Please advice on how to generate a digest (specifically, the Sha256 value) of the file being transferred via this sftp tool?
The counterpart in Java is like this:
MessageDigest messageDigestSha256=MessageDigest.getInstance( "SHA-256");
while ((bytesRead = inStream.read(dataBytes)) != -1) {
outStream.write(dataBytes, 0, bytesRead);
messageDigestSha256.update(dataBytes, 0, bytesRead); // generate digest
}
String EncodedDigestSha256 = Hex.encodeHexString(messageDigestSha256.digest());
...
I know that to generate the Sha256 of a local file, the Go code would be like this:
file, err := os.Open("file.txt")
hash := sha256.New()
_, err := io.Copy(hash, file)
hashBytes := hash.Sum(nil)
But how to get that during the sftp transfer?
BTW, currently I wrote code like below to do file transfer (error handling being removed just to show the major logic):
fDestination, err := sftpClient.Create(destNameRemote)
fSource, err := os.Open(srcNameLocal)
_, err = io.Copy(fDestination, fSource)
or
fSource, err := sftpClient.Open(srcNameRemote)
fDestination, err := os.Create(destNameLocal)
_, err = io.Copy(fDestination, fSource)
Thank you in advance.
Metadata
Metadata
Assignees
Labels
No labels