本文整理汇总了C#中FtpClient.UploadFile方法的典型用法代码示例。如果您正苦于以下问题:C# FtpClient.UploadFile方法的具体用法?C# FtpClient.UploadFile怎么用?C# FtpClient.UploadFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FtpClient
的用法示例。
在下文中一共展示了FtpClient.UploadFile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Upload
/// <summary>
/// Upload one file from local to remote.
/// </summary>
/// <param name="request"></param>
public void Upload(FileTransferRequest request)
{
try
{
CreateRemoteDirectoryForFile(request.RemoteFile);
// upload the file
var credentials = new NetworkCredential(_userId, _password);
using (var ftpClient = new FtpClient {UsePassiveMode = _usePassive, Credentials = credentials})
{
ftpClient.UploadFile(request.RemoteFile, request.LocalFile);
}
}
catch (Exception e)
{
//TODO (cr Oct 2009): we're not supposed to use SR for exception messages.
//Throw a different type of exception and use an ExceptionHandler if it's supposed to be a user message.
var message = string.Format(SR.ExceptionFailedToTransferFile, request.LocalFile, request.RemoteFile);
throw new Exception(message, e);
}
}