///tamir: updated to jcsh-0.1.30
private void _get(String src, OutputStream dst,
SftpProgressMonitor monitor, int mode, long skip)
{ //throws SftpException{
//System.out.println("_get: "+src+", "+dst);
try
{
sendOPENR(src);
Header _header = new Header();
_header = ReadHeader(buf, _header);
int length = _header.length;
int type = _header.type;
buf.Rewind();
fill(buf.buffer, 0, length);
if (type != SSH_FXP_STATUS && type != SSH_FXP_HANDLE)
{
//System.Console.WriteLine("Type is "+type);
throw new SftpException(SSH_FX_FAILURE, "Type is " + type);
}
if (type == SSH_FXP_STATUS)
{
int i = buf.ReadInt();
throwStatusError(buf, i);
}
byte[] handle = buf.ReadString(); // filename
long offset = 0;
if (mode == RESUME)
{
offset += skip;
}
int request_len = 0;
//loop:
while (true)
{
request_len = buf.buffer.Length - 13;
if (ServerVersion == 0) { request_len = 1024; }
sendREAD(handle, offset, request_len);
_header = ReadHeader(buf, _header);
length = _header.length;
type = _header.type;
int i;
if (type == SSH_FXP_STATUS)
{
buf.Rewind();
fill(buf.buffer, 0, length);
i = buf.ReadInt();
if (i == SSH_FX_EOF)
{
goto BREAK;
}
throwStatusError(buf, i);
}
if (type != SSH_FXP_DATA)
{
goto BREAK;
}
buf.Rewind();
fill(buf.buffer, 0, 4); length -= 4;
i = buf.ReadInt(); // length of data
int foo = i;
while (foo > 0)
{
int bar = foo;
if (bar > buf.buffer.Length)
{
bar = buf.buffer.Length;
}
i = io.ins.read(buf.buffer, 0, bar);
if (i < 0)
{
goto BREAK;
}
int data_len = i;
dst.write(buf.buffer, 0, data_len);
offset += data_len;
foo -= data_len;
if (monitor != null)
{
if (!monitor.count(data_len))
{
while (foo > 0)
{
i = io.ins.read(buf.buffer,
0,
(buf.buffer.Length < foo ? buf.buffer.Length : foo));
if (i <= 0) break;
foo -= i;
}
goto BREAK;
}
}
}
//System.out.println("length: "+length); // length should be 0
}
BREAK:
dst.flush();
if (monitor != null) monitor.end();
_sendCLOSE(handle, _header);
}
catch (Exception e)
{
//System.Console.WriteLine(e);
if (e is SftpException) throw (SftpException)e;
throw new SftpException(SSH_FX_FAILURE, "");
}
}