コード例 #1
0
        /// <summary>
        /// Upload all the files within the main directory
        /// </summary>
        private async Task UploadDirectoryFilesAsync(List <FtpResult> filesToUpload, FtpRemoteExists existsMode, FtpVerify verifyOptions, IProgress <FtpProgress> progress, FtpListItem[] remoteListing, CancellationToken token)
        {
            LogFunc(nameof(UploadDirectoryFilesAsync), new object[] { filesToUpload.Count + " files" });

            var r = -1;

            foreach (var result in filesToUpload)
            {
                r++;

                // absorb errors
                try {
                    // check if the file already exists on the server
                    var existsModeToUse = existsMode;
                    var fileExists      = FtpExtensions.FileExistsInListing(remoteListing, result.RemotePath);

                    // if we want to skip uploaded files and the file already exists, mark its skipped
                    if (existsMode == FtpRemoteExists.Skip && fileExists)
                    {
                        LogStatus(FtpTraceLevel.Info, "Skipped file that already exists: " + result.LocalPath);

                        result.IsSuccess = true;
                        result.IsSkipped = true;
                        continue;
                    }

                    // in any mode if the file does not exist, mark that exists check is not required
                    if (!fileExists)
                    {
                        existsModeToUse = existsMode == FtpRemoteExists.Append ? FtpRemoteExists.AppendNoCheck : FtpRemoteExists.NoCheck;
                    }

                    // create meta progress to store the file progress
                    var metaProgress = new FtpProgress(filesToUpload.Count, r);

                    // upload the file
                    var transferred = await UploadFileFromFileAsync(result.LocalPath, result.RemotePath, false, existsModeToUse, false, false, verifyOptions, token, progress, metaProgress);

                    result.IsSuccess = transferred.IsSuccess();
                    result.IsSkipped = transferred == FtpStatus.Skipped;
                }
                catch (Exception ex) {
                    LogStatus(FtpTraceLevel.Warn, "File failed to upload: " + result.LocalPath);

                    // mark that the file failed to upload
                    result.IsFailed  = true;
                    result.Exception = ex;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Upload all the files within the main directory
        /// </summary>
        private void UploadDirectoryFiles(List <FtpResult> filesToUpload, FtpRemoteExists existsMode, FtpVerify verifyOptions, Action <FtpProgress> progress, FtpListItem[] remoteListing)
        {
            LogFunc("UploadDirectoryFiles", new object[] { filesToUpload.Count + " files" });

            foreach (var result in filesToUpload)
            {
                // absorb errors
                try {
                    // check if the file already exists on the server
                    var existsModeToUse = existsMode;
                    var fileExists      = FtpExtensions.FileExistsInListing(remoteListing, result.RemotePath);

                    // if we want to skip uploaded files and the file already exists, mark its skipped
                    if (existsMode == FtpRemoteExists.Skip && fileExists)
                    {
                        LogStatus(FtpTraceLevel.Info, "Skipped file that already exists: " + result.LocalPath);

                        result.IsSuccess = true;
                        result.IsSkipped = true;
                        continue;
                    }

                    // in any mode if the file does not exist, mark that exists check is not required
                    if (!fileExists)
                    {
                        existsModeToUse = existsMode == FtpRemoteExists.Append ? FtpRemoteExists.AppendNoCheck : FtpRemoteExists.NoCheck;
                    }

                    // upload the file
                    var transferred = this.UploadFile(result.LocalPath, result.RemotePath, existsModeToUse, false, verifyOptions, progress);
                    result.IsSuccess = true;
                    result.IsSkipped = !transferred;
                }
                catch (Exception ex) {
                    LogStatus(FtpTraceLevel.Warn, "File failed to upload: " + result.LocalPath);

                    // mark that the file failed to upload
                    result.IsFailed  = true;
                    result.Exception = ex;
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Check if the file is cleared to be uploaded, taking its existance/filesize and existsMode options into account.
        /// </summary>
        private bool CanUploadFile(FtpResult result, FtpListItem[] remoteListing, FtpRemoteExists existsMode, out FtpRemoteExists existsModeToUse)
        {
            // check if the file already exists on the server
            existsModeToUse = existsMode;
            var fileExists = FtpExtensions.FileExistsInListing(remoteListing, result.RemotePath);

            // if we want to skip uploaded files and the file already exists, mark its skipped
            if (existsMode == FtpRemoteExists.Skip && fileExists)
            {
                LogStatus(FtpTraceLevel.Info, "Skipped file that already exists: " + result.LocalPath);

                result.IsSuccess = true;
                result.IsSkipped = true;
                return(false);
            }

            // in any mode if the file does not exist, mark that exists check is not required
            if (!fileExists)
            {
                existsModeToUse = existsMode == FtpRemoteExists.Append ? FtpRemoteExists.AppendNoCheck : FtpRemoteExists.NoCheck;
            }
            return(true);
        }