/// <summary> /// Replicates the <see cref="TVA.Historian.IArchive"/>. /// </summary> protected override void ReplicateArchive() { WriteTrace("Archive replication started"); // Parse FTP client information. Uri replicaUri = new Uri(ReplicaLocation); string[] credentials = replicaUri.UserInfo.Split(':'); // Ensure credentials are supplied. if (credentials.Length != 2) throw new ArgumentException("FTP credentials are missing in ReplicaLocation."); // Create FTP client for uploading. FtpClient ftpClient = new FtpClient(); ftpClient.Server = replicaUri.Host; ftpClient.Port = replicaUri.Port; ftpClient.FileTransferProgress += FtpClient_FileTransferProgress; // Initialize the replication log. WriteTrace("Initializing archive replication log"); DataTable replicationLog = new DataTable("ReplicationRecord"); replicationLog.Columns.Add("DateTime"); replicationLog.Columns.Add("FileName"); replicationLog.Columns.Add("FileHash"); replicationLog.Columns.Add("FileSync"); replicationLog.Columns.Add("HashingTime"); replicationLog.Columns.Add("TransferTime"); replicationLog.Columns.Add("TransferRate"); replicationLog.Columns.Add("ServerRequests"); replicationLog.Columns.Add("ServerResponse"); if (File.Exists(FilePath.GetAbsolutePath(ReplicationLogFile))) replicationLog.ReadXml(FilePath.GetAbsolutePath(ReplicationLogFile)); WriteTrace("Archive replication log initialized"); try { // Connect FTP client to server. WriteTrace("Connecting to ftp://{0}:{1}", ftpClient.Server, ftpClient.Port); ftpClient.Connect(credentials[0], credentials[1]); WriteTrace("Connection successful"); WriteTrace("Changing current directory to '{0}'", replicaUri.AbsolutePath); ftpClient.SetCurrentDirectory(replicaUri.LocalPath); WriteTrace("Current directory changed to '{0}'", ftpClient.CurrentDirectory.FullPath); // Process all archive location(s). foreach (string folder in ArchiveLocation.Split(';')) { if (!string.IsNullOrEmpty(folder)) ReplicateToHadoop(ftpClient, folder.Trim(), replicationLog); } } finally { ftpClient.Dispose(); replicationLog.WriteXml(FilePath.GetAbsolutePath(ReplicationLogFile)); } WriteTrace("Archive replication complete"); }
/// <summary> /// Clones FTP session used by file watcher so it can be used for other purposes. /// </summary> /// <returns>New connected FTP session matching settings defined for FTP file watcher.</returns> public virtual FtpClient CloneFtpSession() { // This method is just for convenience. We can't allow the end user to use the // actual internal directory for sending files or other work because it is // constantly being refreshed/used etc., so we instead create a new FTP Session // based on the current internal session and watch directory information FtpClient newSession = new FtpClient(m_session.CaseInsensitive); newSession.Server = m_session.Server; newSession.Connect(m_username, m_password); newSession.SetCurrentDirectory(m_watchDirectory); return newSession; }