本文整理汇总了C#中System.Net.FtpWebRequest.ContentOffset属性的典型用法代码示例。如果您正苦于以下问题:C# FtpWebRequest.ContentOffset属性的具体用法?C# FtpWebRequest.ContentOffset怎么用?C# FtpWebRequest.ContentOffset使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Net.FtpWebRequest
的用法示例。
在下文中一共展示了FtpWebRequest.ContentOffset属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RestartDownloadFromServer
public static bool RestartDownloadFromServer(string fileName, Uri serverUri, long offset)
{
// The serverUri parameter should use the ftp:// scheme.
// It identifies the server file that is to be downloaded
// Example: ftp://contoso.com/someFile.txt.
// The fileName parameter identifies the local file.
//The serverUri parameter identifies the remote file.
// The offset parameter specifies where in the server file to start reading data.
if (serverUri.Scheme != Uri.UriSchemeFtp)
{
return false;
}
// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverUri);
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.ContentOffset = offset;
FtpWebResponse response = null;
try
{
response = (FtpWebResponse) request.GetResponse();
}
catch (WebException e)
{
Console.WriteLine (e.Status);
Console.WriteLine (e.Message);
return false;
}
// Get the data stream from the response.
Stream newFile = response.GetResponseStream();
// Use a StreamReader to simplify reading the response data.
StreamReader reader = new StreamReader(newFile);
string newFileData = reader.ReadToEnd();
// Append the response data to the local file
// using a StreamWriter.
StreamWriter writer = File.AppendText(fileName);
writer.Write(newFileData);
// Display the status description.
// Cleanup.
writer.Close();
reader.Close();
response.Close();
Console.WriteLine("Download restart - status: {0}",response.StatusDescription);
return true;
}