public FtpFileInfo(FtpConnection ftp, string filePath)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException("filePath");
            }

            this.OriginalPath = filePath;
            this.FullPath = filePath;
            this.ftpConnection = ftp;
            this.fileName = Path.GetFileName(filePath);
        }
示例#2
0
        /// <summary>
        /// Upload Files
        /// </summary>
        private void UploadFiles()
        {
            if (this.FileNames == null)
            {
                throw new ArgumentException("Required  parameter missing: FileNames.");
            }

            using (FtpConnection ftpConnection = this.CreateFtpConnection())
            {
                this.LogBuildMessage("Uploading Files", BuildMessageImportance.Low);

                if (!string.IsNullOrEmpty(this.WorkingDirectory.Get(this.ActivityContext)))
                {
                    this.LogBuildMessage(string.Format(CultureInfo.CurrentCulture, "Setting Working Directory: {0}", this.WorkingDirectory.Get(this.ActivityContext)), BuildMessageImportance.Low);
                    FtpConnection.SetLocalDirectory(this.WorkingDirectory.Get(this.ActivityContext));
                }

                ftpConnection.LogOn();
                if (!string.IsNullOrEmpty(this.RemoteDirectoryName.Get(this.ActivityContext)))
                {
                    this.LogBuildMessage(string.Format(CultureInfo.CurrentCulture, "Setting Current Directory: {0}", this.RemoteDirectoryName.Get(this.ActivityContext)), BuildMessageImportance.Low);
                    ftpConnection.SetCurrentDirectory(this.RemoteDirectoryName.Get(this.ActivityContext));
                }

                foreach (string fileName in this.FileNames.Get(this.ActivityContext))
                {
                    try
                    {
                        if (File.Exists(fileName))
                        {
                            this.LogBuildMessage(string.Format(CultureInfo.CurrentCulture, "Uploading: {0}", fileName), BuildMessageImportance.Low);
                            ftpConnection.PutFile(fileName);
                        }
                    }
                    catch (FtpException ex)
                    {
                        this.LogBuildWarning(string.Format(CultureInfo.CurrentCulture, "There was an error uploading file: {0}. The Error Details are \"{1}\" and error code is {2} ", fileName, ex.Message, ex.ErrorCode));
                    }
                }
            }
        }
示例#3
0
        /// <summary>
        /// Delete given files from the FTP Directory
        /// </summary>
        private void DeleteFiles()
        {
            if (this.FileNames == null)
            {
                throw new ArgumentException("Required  parameter missing: RemoteDirectoryName.");
            }

            using (FtpConnection ftpConnection = this.CreateFtpConnection())
            {
                ftpConnection.LogOn();
                this.LogBuildMessage("Deleting Files", BuildMessageImportance.Low);
                if (!string.IsNullOrEmpty(this.RemoteDirectoryName.Get(this.ActivityContext)))
                {
                    this.LogBuildMessage(string.Format(CultureInfo.CurrentCulture, "Setting Current Directory: {0}", this.RemoteDirectoryName.Get(this.ActivityContext)), BuildMessageImportance.Low);
                    ftpConnection.SetCurrentDirectory(this.RemoteDirectoryName.Get(this.ActivityContext));
                }

                foreach (string fileName in this.FileNames.Get(this.ActivityContext))
                {
                    try
                    {
                        this.LogBuildMessage(string.Format(CultureInfo.CurrentCulture, "Setting Current Directory: {0}", this.RemoteDirectoryName), BuildMessageImportance.Low);
                        ftpConnection.DeleteFile(fileName);
                    }
                    catch (FtpException ex)
                    {
                        if (ex.Message.Contains("550"))
                        {
                            continue;
                        }

                        this.LogBuildWarning(string.Format(CultureInfo.CurrentCulture, "There was an error in deleting file: {0}. The Error Details are \"{1}\" and error code is {2} ", fileName, ex.Message, ex.ErrorCode));
                    }
                }
            }
        }
 public FtpDirectoryInfo(FtpConnection ftp, string path)
 {
     this.FtpConnection = ftp;
     this.FullPath      = path;
 }
 public FtpDirectoryInfo(FtpConnection ftp, string path)
 {
     this.FtpConnection = ftp;
     this.FullPath = path;
 }