Jon Knight - 2011-06-06

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).");
}