SetCurrentDirectory() public method

Changes the current FTP session directory to the specified path.
public SetCurrentDirectory ( string directoryPath ) : void
directoryPath string New directory.
return void
Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
        private void ConnectToWatchDirectory()
        {
            if (m_session.IsConnected)
            {
                m_session.SetCurrentDirectory(m_watchDirectory);

                if (m_watchDirectory.Length > 0)
                {
                    OnStatus("FTP file watcher monitoring directory \"" + m_watchDirectory + "\"");
                }
                else
                {
                    OnStatus("No FTP file watcher directory specified - monitoring initial folder");
                }
            }
        }
Esempio n. 3
0
        /// <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;
        }
Esempio n. 4
0
        /// <summary>
        /// Replicates the <see cref="GSF.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");
        }