Exemple #1
0
 public static void FtpDownloadComplete(object sender, FtpDownloadCompleteEventArgs e)
 {
     m_Logger.DebugFormat("Enter NotifyEngine.FtpDownloadComplete");
     NotifyAdmin.FtpDownloadComplete(e.User, e.ServerMessages);
     m_Logger.DebugFormat("Exit NotifyEngine.FtpDownloadComplete");
 }
        private void DoUpload()
        {
            try
            {
                using (FTPConnection ftp = new FTPConnection())
                {
                    ftp.ServerAddress             = Host;
                    ftp.ServerPort                = Port;
                    ftp.UserName                  = Username;
                    ftp.Password                  = Password;
                    ftp.AutoPassiveIPSubstitution = PassiveMode;

                    ftp.ReplyReceived += new FTPMessageHandler(ServerResponse);

                    ftp.Connect();

                    if (!StringUtils.IsBlank(RemoteFolder))
                    {
                        ftp.ChangeWorkingDirectory(RemoteFolder);
                    }

                    int count = 0;

                    foreach (FtpFile file in Files)
                    {
                        m_Logger.DebugFormat("Uploading {0} (file {1}/{2}) to {3} for {4}", file, count + 1, Files.Count, Host, User.FullName);

                        if (StringUtils.IsBlank(file.LocalPath))
                        {
                            m_Logger.Warn("File LocalPath is empty. Nothing to upload.");
                            continue;
                        }

                        if (!File.Exists(file.LocalPath))
                        {
                            m_Logger.WarnFormat("Asset File '{0}' does not exist. Nothing to upload.", file.LocalPath);
                            continue;
                        }

                        m_Logger.DebugFormat("Uploading {0} to FTP server...", file.LocalPath);
                        ftp.UploadFile(file.LocalPath, file.RemoteFilename);
                        m_Logger.Debug("...Done");

                        count++;
                    }

                    ftp.Close();

                    m_Logger.DebugFormat("Uploaded {0} files to {1} for {2}", count, Host, User.FullName);
                }

                if (UploadComplete != null)
                {
                    FtpDownloadCompleteEventArgs e = new FtpDownloadCompleteEventArgs {
                        ServerMessages = m_ServerResponses.ToString(), User = User
                    };
                    UploadComplete(this, e);
                }
            }
            catch (Exception ex)
            {
                // Initialise error message
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("An error occured when doing an FTP transfer");

                // Add the error message
                sb.AppendLine(ex.ToString());
                sb.AppendLine();

                // Add the server messages
                sb.Append(m_ServerResponses.ToString());
                sb.AppendLine();

                string message = sb.ToString();

                m_Logger.Error(message, ex);
            }
        }