private AdjustRemoteFilename ( string remoteFilename ) : string | ||
remoteFilename | string | |
return | string |
/// <summary> /// <paramref name="ftpClient"/>를 이용하여, 로컬 파일 스트림을 FTP 서버로 Upload 합니다. /// </summary> /// <param name="ftpClient"></param> /// <param name="localStream"></param> /// <param name="remoteFilename"></param> /// <returns></returns> public static Task <bool> UploadTask(this FtpClient ftpClient, Stream localStream, string remoteFilename) { if (IsDebugEnabled) { log.Debug("FTP 서버로 스트림을 비동기 방식으로 업로드합니다... RemoteFile=[{0}]", remoteFilename); } localStream.ShouldNotBeNull("localStream"); remoteFilename = ftpClient.AdjustRemoteFilename(remoteFilename); var uri = ftpClient.Hostname + remoteFilename; return (GetRequestStreamTask(ftpClient, uri, WebRequestMethods.Ftp.UploadFile) .ContinueWith(task => { localStream.CopyStreamToStream(task.Result); task.Result.Close(); if (IsDebugEnabled) { log.Debug("FTP 서버로 파일을 업로드를 완료했습니다. RemoteFile=[{0}]", remoteFilename); } return true; }, TaskContinuationOptions.ExecuteSynchronously)); }
/// <summary> /// FTP 서버에 있는 원격 파일을 다운로드하여, <paramref name="localStream"/>에 씁니다. /// </summary> /// <param name="ftpClient"></param> /// <param name="remoteFilename"></param> /// <param name="localStream"></param> /// <returns></returns> public static Task <bool> DownloadTask(this FtpClient ftpClient, string remoteFilename, Stream localStream) { localStream.ShouldNotBeNull("localStream"); if (IsDebugEnabled) { log.Debug("원격 파일을 다운로드 받는 작업을 생성합니다... remoteFilename=[{0}]", remoteFilename); } remoteFilename = ftpClient.AdjustRemoteFilename(remoteFilename); var uri = ftpClient.Hostname + remoteFilename; return (ftpClient .GetResponseStreamTask(uri, WebRequestMethods.Ftp.DownloadFile) .ContinueWith(task => { task.Result.CopyStreamToStream(localStream); task.Result.Close(); if (IsDebugEnabled) { log.Debug("원격 파일 다운로드가 완료되었습니다. remoteFilename=[{0}]", remoteFilename); } return true; }, TaskContinuationOptions.ExecuteSynchronously)); }