public long DoDownload()
{
Byte[] bytes = new Byte[512];
long bytes_got;
try
{
bytes_got = data_sock.Receive(bytes, bytes.Length, 0);
if (bytes_got <= 0)
{
// the download is done or an error occured
CloseDataSocket();
file.Close();
file = null;
ReadResponse();
switch (response)
{
case 226:
case 250:
break;
default:
throw new Exception(responseStr);
}
SetBinaryMode(false);
return bytes_got;
}
file.Write(bytes, 0, (int)bytes_got);
bytes_total += bytes_got;
}
catch (Exception ex)
{
CloseDataSocket();
file.Close();
file = null;
ReadResponse();
SetBinaryMode(false);
throw ex;
}
return bytes_got;
}
}