本文整理汇总了C#中System.Net.FtpWebResponse.ResponseUri属性的典型用法代码示例。如果您正苦于以下问题:C# FtpWebResponse.ResponseUri属性的具体用法?C# FtpWebResponse.ResponseUri怎么用?C# FtpWebResponse.ResponseUri使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Net.FtpWebResponse
的用法示例。
在下文中一共展示了FtpWebResponse.ResponseUri属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DownloadFileFromServer
public static bool DownloadFileFromServer(Uri serverUri, string localFileName)
{
// The serverUri parameter should start with the ftp:// scheme.
if (serverUri.Scheme != Uri.UriSchemeFtp)
{
return false;
}
// Get the object used to communicate with the server.
// Note that the cast to FtpWebRequest is done only
// for the purposes of illustration. If your application
// does not set any properties other than those defined in the
// System.Net.WebRequest class, you can use the following line instead:
// WebRequest request = WebRequest.Create(serverUri);
//
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverUri);
request.Method = WebRequestMethods.Ftp.DownloadFile;
FtpWebResponse response = (FtpWebResponse) request.GetResponse();
Stream responseStream = null;
StreamReader readStream = null;
StreamWriter writeStream = null;
try
{
responseStream = response.GetResponseStream();
readStream = new StreamReader(responseStream, System.Text.Encoding.UTF8);
// Display information about the data received from the server.
Console.WriteLine("Bytes received: {0}",response.ContentLength);
Console.WriteLine("Message from server: {0}", response.StatusDescription);
Console.WriteLine("Resource: {0}", response.ResponseUri);
// Write the bytes received from the server to the local file.
if (readStream != null)
{
writeStream = new StreamWriter(localFileName, false);
writeStream.Write(readStream.ReadToEnd());
}
}
finally
{
if (readStream != null)
{
readStream.Close();
}
if (response != null)
{
response.Close();
}
if (writeStream != null)
{
writeStream.Close();
}
}
return true;
}