private void UploadTemplateFiles()
        {
            string templateDirectory = DirectoryHelper.ReleaseDirectory + @"ZippedTemplates/";

            using (var client = SftpManager.GetClient(host, Username, Password))
            {
                client.Connect();


                foreach (var file in Directory.GetFiles(templateDirectory, "*.zip"))
                {
                    var fileName = FileManager.RemovePath(file);

                    string localFile   = templateDirectory + fileName;
                    string destination = _ftpFolder + "ZippedTemplates/" + fileName;
                    SftpManager.UploadFileWithOpenConnection(
                        localFile, destination, client);


                    Results.WriteMessage(file + " uploaded to " + destination);
                }

                client.Disconnect();
            }
        }
        private void UploadEngineFiles()
        {
            List <CopyInformation> engineFiles = CopyBuiltEnginesToReleaseFolder.CopyInformationList;

            using (var client = SftpManager.GetClient(host, Username, Password))
            {
                client.Connect();
                for (int i = 0; i < engineFiles.Count; i++)
                {
                    string localFile = engineFiles[i].DestinationFile;

                    string engineName     = FileManager.RemovePath(FileManager.GetDirectory(localFile));
                    string debugOrRelease = null;
                    if (engineName.ToLower() == "debug/" || engineName.ToLower() == "release/")
                    {
                        debugOrRelease = engineName;
                        engineName     = FileManager.RemovePath(FileManager.GetDirectory(FileManager.GetDirectory(localFile)));
                    }


                    string fileName = engineName + debugOrRelease +
                                      FileManager.RemovePath(localFile);
                    string destination = _ftpFolder + "SingleDlls/" + fileName;

                    SftpManager.UploadFileWithOpenConnection(
                        localFile, destination, client);


                    Results.WriteMessage(engineFiles[i].DestinationFile + " uploaded to " + destination);
                }
                client.Disconnect();
            }
        }
        private void UploadFrbdkFiles()
        {
            string localFile = ZipFrbdk.DestinationFile;

            string fileName = _ftpFolder + FileManager.RemovePath(localFile);

            SftpManager.UploadFile(
                localFile, host, fileName, Username, Password);

            Results.WriteMessage(localFile + " uploaded to " + fileName);
        }
        private void UploadGumFiles()
        {
            string localFile = FileManager.GetDirectory(DirectoryHelper.GumBuildDirectory) + "Gum.zip";

            string targetFile = gumFolder + FileManager.RemovePath(localFile);

            SftpManager.UploadFile(
                localFile, host, targetFile, Username, Password);

            Results.WriteMessage(localFile + " uploaded to " + targetFile);
        }
        private void DeleteDirectory(string relativeDirectory)
        {
            //Get files
            var files = SftpManager.GetList(host, relativeDirectory, Username, Password);

            //Loop through files
            foreach (var fileStruct in files)
            {
                //If directory, need to delete sub directories
                if (fileStruct.IsDirectory)
                {
                    DeleteDirectory(relativeDirectory + "/" + fileStruct.Name);
                }
                else
                {
                    SftpManager.DeleteRemoteFile(host, fileStruct.Name, Username, Password);
                }
            }

            SftpManager.DeleteRemoteDirectory(host, relativeDirectory, Username, Password);
        }
        private void CleanUpBackups()
        {
            //Get files in folder
            var files = SftpManager.GetList(host, _backupFolder, Username, Password);

            //Filename structure
            var exp = new Regex(@"^build_\d\d\d\d_\d\d_\d\d_\d\d$");

            //Loop through directory
            foreach (var fileStruct in files)
            {
                //If a directory and matches filename structure
                if (fileStruct.IsDirectory && exp.IsMatch(fileStruct.Name))
                {
                    //Get year
                    var year = int.Parse(fileStruct.Name.Substring(6, 4));

                    //Get month
                    var month = int.Parse(fileStruct.Name.Substring(11, 2));

                    //Get day
                    var day = int.Parse(fileStruct.Name.Substring(14, 2));

                    //Get version
                    var version = int.Parse(fileStruct.Name.Substring(17, 2));

                    //Get date from file name
                    var date = new DateTime(year, month, day);

                    //If past expiration date
                    if (date < _deleteBeforeDate)
                    {
                        //Remove file from server
                        DeleteDirectory(_backupFolder + fileStruct.Name);
                    }
                }
            }
        }
示例#7
0
 public SFTPFileTransferAdapter(IAdaperSetting AdaperSettings)
 {
     _adaperSettings = AdaperSettings;
     objSftpManager  = new SftpManager(_adaperSettings);
 }
        public static void BuildBackupFile()
        {
            string localPath = Path.GetTempPath() + @"\BackupFolders.txt";

            StreamWriter sw;

            sw = File.CreateText(localPath);

            //    //Filename structure
            var exp = new Regex(@"^build_\d\d\d\d_\d\d_\d\d_\d\d$");

            //    //Daily Builds
            var files =
                SftpManager.GetList(host, "files.flatredball.com/content/FrbXnaTemplates/DailyBackups/", Username, Password);
            var folderNames = (from fileStruct in files where fileStruct.IsDirectory && exp.IsMatch(fileStruct.Name) select fileStruct.Name).ToList();

            folderNames.Reverse();
            foreach (var folderName in folderNames)
            {
                //Get year
                var year = int.Parse(folderName.Substring(6, 4));

                //Get month
                var month = int.Parse(folderName.Substring(11, 2));

                //Get day
                var day = int.Parse(folderName.Substring(14, 2));

                //Get version
                var version = int.Parse(folderName.Substring(17, 2));

                sw.WriteLine("Daily Build - " + month + @"/" + day + @"/" + year + " " + version + ",DailyBackups/" + folderName + "/");
            }

            //Weekly Builds
            files       = SftpManager.GetList(host, "files.flatredball.com/content/FrbXnaTemplates/WeeklyBackups/", Username, Password);
            folderNames = (from fileStruct in files where fileStruct.IsDirectory && exp.IsMatch(fileStruct.Name) select fileStruct.Name).ToList();
            folderNames.Reverse();
            foreach (var folderName in folderNames)
            {
                //Get year
                var year = int.Parse(folderName.Substring(6, 4));

                //Get month
                var month = int.Parse(folderName.Substring(11, 2));

                //Get day
                var day = int.Parse(folderName.Substring(14, 2));

                //Get version
                var version = int.Parse(folderName.Substring(17, 2));

                sw.WriteLine("Weekly Build - " + month + @"/" + day + @"/" + year + " " + version + ",WeeklyBackups/" + folderName + "/");
            }

            //Monthly Builds
            files = SftpManager.GetList(
                host, "files.flatredball.com/content/FrbXnaTemplates/MonthlyBackups/", Username, Password);
            folderNames = (from fileStruct in files where fileStruct.IsDirectory && exp.IsMatch(fileStruct.Name) select fileStruct.Name).ToList();
            folderNames.Reverse();
            foreach (var folderName in folderNames)
            {
                //Get year
                var year = int.Parse(folderName.Substring(6, 4));

                //Get month
                var month = int.Parse(folderName.Substring(11, 2));

                //Get day
                var day = int.Parse(folderName.Substring(14, 2));

                //Get version
                var version = int.Parse(folderName.Substring(17, 2));

                sw.WriteLine("Monthly Build - " + month + @"/" + day + @"/" + year + " " + version + ",MonthlyBackups/" + folderName + "/");
            }

            sw.Close();

            //SftpManager.UploadFile(localPath, host, _backupFile, Username, Password);
        }
        private bool FolderExists(string fileName)
        {
            var files = SftpManager.GetList(host, _backupFolder, Username, Password);

            return(files.Any(fileStruct => "sftp://files.flatredball.com/" + _backupFolder + fileStruct.Name == fileName));
        }