Exemple #1
0
        /// <summary>
        /// 원격 파일의 크기를 조회합니다.
        /// </summary>
        /// <param name="ftpClient"></param>
        /// <param name="remoteFilename"></param>
        /// <returns></returns>
        public static Task <long> GetFileSizeTask(this FtpClient ftpClient, string remoteFilename)
        {
            if (IsDebugEnabled)
            {
                log.Debug("원격 파일의 크기를 조회합니다... remoteFilename=[{0}]", remoteFilename);
            }

            var uri = ftpClient.Hostname + ftpClient.GetFullPath(remoteFilename);

            return
                (ftpClient
                 .GetResponseTask(uri, WebRequestMethods.Ftp.GetFileSize)
                 .ContinueWith(task => {
                var fileSize = task.Result.ContentLength;
                task.Result.Close();

                if (IsDebugEnabled)
                {
                    log.Debug("원격 파일[{0}] 의 크기는 [{1}] bytes", remoteFilename, fileSize);
                }

                return fileSize;
            },
                               TaskContinuationOptions.ExecuteSynchronously));
        }
Exemple #2
0
 /// <summary>
 /// 요청만을 보냅니다.
 /// </summary>
 /// <param name="ftpClient"></param>
 /// <param name="uri"></param>
 /// <param name="method"></param>
 public static Task SendRequestOnlyTask(this FtpClient ftpClient, string uri, string method)
 {
     return
         (ftpClient
          .GetResponseTask(uri, method)
          .ContinueWith(task => task.Result.Close(),
                        TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnRanToCompletion));
 }
Exemple #3
0
        /// <summary>
        /// 원격 파일을 비동기 방식으로 삭제합니다.
        /// </summary>
        /// <param name="ftpClient"></param>
        /// <param name="remoteFilename">삭제할 파일명</param>
        /// <returns></returns>
        public static Task <bool> DeleteFileTask(this FtpClient ftpClient, string remoteFilename)
        {
            if (IsDebugEnabled)
            {
                log.Debug("FTP 서버에 있는 원격 파일을 삭제하는 작업을 생성합니다... 원격파일=[{0}]", remoteFilename);
            }

            var uri = ftpClient.Hostname + ftpClient.GetFullPath(remoteFilename);

            return
                (ftpClient
                 .GetResponseTask(uri, WebRequestMethods.Ftp.DeleteFile)
                 .ContinueWith(task => {
                var result = task.IsCompleted;
                task.Result.Close();
                return result;
            },
                               TaskContinuationOptions.ExecuteSynchronously));
        }
Exemple #4
0
        /// <summary>
        /// FTP 서버의 원격 파일명을 변경합니다.
        /// </summary>
        /// <param name="ftpClient"></param>
        /// <param name="srcFilename"></param>
        /// <param name="destFilename"></param>
        /// <returns></returns>
        public static Task <bool> RenameFileTask(this FtpClient ftpClient, string srcFilename, string destFilename)
        {
            srcFilename.ShouldNotBeWhiteSpace("srcFilename");
            destFilename.ShouldNotBeWhiteSpace("destFilename");

            if (IsDebugEnabled)
            {
                log.Debug("원격 파일명을 변경합니다... srcFilename=[{0}], destFilename=[{1}]", srcFilename, destFilename);
            }

            var src  = ftpClient.GetFullPath(srcFilename);
            var dest = ftpClient.GetFullPath(destFilename);

            if (src == dest)
            {
                return(Task.Factory.FromResult(true));
            }

            var request = ftpClient.GetRequest(src);

            request.Method   = WebRequestMethods.Ftp.Rename;
            request.RenameTo = destFilename;

            return
                (ftpClient
                 .GetResponseTask(request)
                 .ContinueWith(task => {
                var result = task.IsCompleted;
                task.Result.Close();

                if (IsDebugEnabled)
                {
                    log.Debug("원격 파일명을 비동기 방식으로 변경했습니다!!! srcFilename=[{0}], destFilename=[{1}]", srcFilename,
                              destFilename);
                }

                return result;
            },
                               TaskContinuationOptions.ExecuteSynchronously));
        }