日期:2014-05-17 浏览次数:21188 次
FileStream input = new FileStream(fileName,FileMode.Open,FileAccess.Read);
if ( resume && input.Length < offset )
{
// different file size
Debug.WriteLine("Overwriting " + fileName, "FtpClient");
offset = 0;
}
else if ( resume && input.Length == offset )
{
// file done
input.Close();
Debug.WriteLine("Skipping completed " + fileName + " - turn resume off to not detect.", "FtpClient");
return;
}
// dont create untill we know that we need it
cSocket = this.createDataSocket();
if ( offset > 0 )
{
this.sendCommand( "REST " + offset );
if ( this.resultCode != 350 )
{
Debug.WriteLine("Resuming not supported", "FtpClient");
offset = 0;
}
}
this.sendCommand( "STOR " + Path.GetFileName(fileName) );
if ( this.resultCode != 125 && this.resultCode != 150 ) throw new FtpException(result.Substring(4));//zonghw
if ( offset != 0 )
{
Debug.WriteLine("Resuming at offset " + offset, "FtpClient" );
input.Seek(offset,SeekOrigin.Begin);
}
Debug.WriteLine( "Uploading file " + fileName + " to " + remotePath, "FtpClient" );
while ((bytes = input.Read(buffer,0,buffer.Length)) > 0)
{
cSocket.Send(buffer, bytes, 0);
}
input.Close();
if (cSocket.Connected)
{
cSocket.Close();
}
this.readResponse();
if( this.resultCode != 226 && this.resultCode != 250 ) throw new FtpException(this.result.Substring(4));