当前位置: 首页>>代码示例>>C#>>正文


C# FtpWebRequest.BeginGetRequestStream方法代码示例

本文整理汇总了C#中System.Net.FtpWebRequest.BeginGetRequestStream方法的典型用法代码示例。如果您正苦于以下问题:C# FtpWebRequest.BeginGetRequestStream方法的具体用法?C# FtpWebRequest.BeginGetRequestStream怎么用?C# FtpWebRequest.BeginGetRequestStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.FtpWebRequest的用法示例。


在下文中一共展示了FtpWebRequest.BeginGetRequestStream方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

// Command line arguments are two strings:
// 1. The url that is the name of the file being uploaded to the server.
// 2. The name of the file on the local machine.
//
public static void Main(string[] args)
{
    // Create a Uri instance with the specified URI string.
    // If the URI is not correctly formed, the Uri constructor
    // will throw an exception.
    ManualResetEvent waitObject;
    
    Uri target = new Uri (args[0]);
    string fileName = args[1];
    FtpState state = new FtpState();
    FtpWebRequest request = (FtpWebRequest)WebRequest.Create(target);
    request.Method = WebRequestMethods.Ftp.UploadFile;
    
    // This example uses anonymous logon.
    // The request is anonymous by default; the credential does not have to be specified. 
    // The example specifies the credential only to
    // control how actions are logged on the server.
    
    request.Credentials = new NetworkCredential ("anonymous","janeDoe@contoso.com");
    
    // Store the request in the object that we pass into the
    // asynchronous operations.
    state.Request = request;
    state.FileName = fileName;
    
    // Get the event to wait on.
    waitObject = state.OperationComplete;
    
    // Asynchronously get the stream for the file contents.
    request.BeginGetRequestStream(
        new AsyncCallback (EndGetStreamCallback), 
        state
    );
    
    // Block the current thread until all operations are complete.
    waitObject.WaitOne();
    
    // The operations either completed or threw an exception.
    if (state.OperationException != null)
    {
        throw state.OperationException;
    }
    else
    {
        Console.WriteLine("The operation completed - {0}", state.StatusDescription);
    }
}
开发者ID:.NET开发者,项目名称:System.Net,代码行数:51,代码来源:FtpWebRequest.BeginGetRequestStream


注:本文中的System.Net.FtpWebRequest.BeginGetRequestStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。