Example #1
0
        private void _DownLoadAndProcessPositionFiles()
        {
            GatLogger.Instance.AddMessage("Pulling today's position files.", LogMode.LogAndScreen);

            Ftp ftpHandle = new Ftp("54.245.114.32", "usr_vtbullseye", "rod30cl0wn!");

            ftpHandle.ChangeRemoteWorkingDirectory("PositionFiles");

            string        fileDateString = DateTime.Now.ToString("yyMMdd");
            List <string> downloadedList = new List <string>();

            foreach (IRemoteFile remoteFile in ftpHandle.GetWorkingDirContents())
            {
                if (remoteFile.Filename.Contains(fileDateString))
                {
                    GatLogger.Instance.AddMessage(string.Format("Found file {0}", remoteFile.Filename), LogMode.LogAndScreen);

                    string downloadedFile = GatFile.Path(Dir.Temp, remoteFile.Filename);
                    ftpHandle.Pull(remoteFile.Filename, Path.GetDirectoryName(downloadedFile));

                    if (File.Exists(downloadedFile))
                    {
                        downloadedList.Add(downloadedFile);
                        _ProcessPositionFile(downloadedFile);
                    }
                }
            }

            Thread.Sleep(3000);

            foreach (string file in downloadedList)
            {
                File.Delete(file);
            }
        }
        public void FtpConnectionTest()
        {
            IFtpHandle ftpConnection = new Ftp("54.245.114.32", "DailyFiles", "d@yDump!", 21, "/Temp", "ConnectionTest");

            Assert.AreEqual((int)ftpConnection.ConnectionStatus, (int)FtpStatus.Connected);

            List <IRemoteFile> files      = ftpConnection.GetWorkingDirContents();
            string             localPath  = ftpConnection.LocalWorkingDirectory;
            string             remotePath = ftpConnection.RemoteWorkingDirectory;

            ftpConnection.Pull(files.First().Filename);
            string[] localFiles = Directory.GetFiles(localPath);
            Assert.AreNotEqual(0, localFiles.Count());
            Assert.AreEqual(files.First().Filename, Path.GetFileName(localFiles[0]));

            ftpConnection.ChangeRemoteWorkingDirectory("Archive");
            Assert.AreNotEqual(remotePath, ftpConnection.RemoteWorkingDirectory);
            files = ftpConnection.GetWorkingDirContents();
            ftpConnection.Pull(files.First().Filename);
            localFiles = Directory.GetFiles(localPath);
            Assert.AreEqual(2, localFiles.Count());

            ftpConnection.ChangeLocalWorkingDirectory(GatFile.Path(Dir.Data, string.Empty));
            localPath = ftpConnection.LocalWorkingDirectory;
            ftpConnection.Pull(files.First().Filename);
            localFiles = Directory.GetFiles(localPath);
            Assert.AreNotEqual(0, localFiles.Count());

            localPath = GatFile.Path(Dir.Root, string.Empty);
            ftpConnection.Pull(files.First().Filename, localPath);
            localFiles = Directory.GetFiles(localPath);
            Assert.AreNotEqual(0, localFiles.Count());

            ftpConnection.ResetToRootDirectory();
            Assert.AreEqual(remotePath, ftpConnection.RemoteWorkingDirectory);

            files = ftpConnection.GetWorkingDirContents();
            foreach (var file in files)
            {
                ftpConnection.Pull(file.Filename);
                ftpConnection.Push(Path.Combine(ftpConnection.LocalWorkingDirectory, file.Filename), "Archive");
            }
        }