When I transfer files using sharpssh to openssh, the file that arrives is corrupt. When comparing the file transfered to a file transfered with say Winscp, the bytes match exactly, but the md5's are different. So far in testing, this only seems to happen with compressed files (tar, zip). When I transfer text files whioch contain all 255 characters, it transfers fine and the md5's match with the winscp transfered file
I realise that this is an old issue, but in case anyone is interested there seems to be a bug in the SCP_ReceiveFile procedure in the Scp.cs file. The code is storing the number of bytes read, but then using the buffer size when writing to the local file, and updating the filesize.
I changed this to the following on my local copy:
/// <summary>
/// Transfer a file from the remote server
/// </summary>
/// <param name="server">A connected server I/O stream</param>
/// <param name="rfile">The remote file to copy</param>
/// <param name="lfile">The local destination path</param>
protected void SCP_ReceiveFile(Stream server, string rfile, string lfile, int size)
{
int copied = 0;
SendStartMessage(rfile, lfile, size, "Connected, starting transfer.");
// read a content of lfile
FileStream fos=File.OpenWrite(lfile);
int filesize=size;
byte[] buf = new byte[1024];
int bufferLength = buf.Length;
while(!m_cancelled)
{
if (bufferLength > filesize)
bufferLength = filesize;
int len=server.Read(buf, 0, bufferLength);
copied += len;
fos.Write(buf, 0, len);
SendProgressMessage(rfile, lfile, copied, size, "Transferring...");
filesize-=len;
if(filesize==0) break;
}
fos.Close();
if(m_cancelled)
return;
SCP_CheckAck(server);
SendEndMessage(rfile, lfile, copied, size, "Transfer completed successfully ("+filesize+" bytes).");
}