Asp tutorial. net file resumable upload code
Ftpwebrequest ftprequest = (ftpwebrequest) webrequest. create (_ uri );
Ftprequest. method = webrequestmethods. ftp. downloadfile;
Ftprequest. keepalive = false;
Ftprequest. usebinary = true;
Ftprequest. contentoffset = segment. begin;
Ftprequest. credentials = new networkcredential (_ username, _ password );
Using (ftpwebresponse ftpresponse = (ftpwebresponse) ftprequest. getresponse ())
Using (filestream file = new filestream (savetemppath, filemode. open, fileaccess. write, fileshare. write ))
Using (stream responsestream = ftpresponse. getresponsestream ())
{
File. seek (segment. begin, seekorigin. begin );
Int poswrite = segment. begin;
Byte [] buf = new byte [_ bufsize];
Int readbytes = 0;
While (! Responsestream. canread)
{
Thread. sleep (0 );
}
While (readbytes = responsestream. read (buf, 0, buf. length)> 0)
{
Int byteslack = segment. end-poswrite + 1;
If (readbytes> byteslack)
{
File. write (buf, 0, byteslack );
Poswrite + = byteslack;
}
Else
{
File. write (buf, 0, buf. length );
Poswrite + = buf. length;
}
File. flush ();
Segment. begin = poswrite;
// Todo: save segment
If (poswrite> segment. end)
{
Break;
}
While (! Responsestream. canread)
{
Thread. sleep (0 );
}
}
Responsestream. close ();
File. close ();
Ftpresponse. close ();
// Indicate that contentoffset must be set.