當前位置: 首頁>>代碼示例>>C#>>正文


C# FtpWebResponse.ResponseUri屬性代碼示例

本文整理匯總了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;
}
開發者ID:.NET開發者,項目名稱:System.Net,代碼行數:56,代碼來源:FtpWebResponse.ResponseUri


注:本文中的System.Net.FtpWebResponse.ResponseUri屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。