Пример #1
0
        //Delete
        public void Delete(string filePath)
        {
            if (RecordsetHandler.RecordsetEnabled)
            {
                IEnumerable <string> listOfFiles = RecordsetHandler.GetValues();
                if (listOfFiles != null)
                {
                    ComponentEvents.FireInformation(0, "SSISSFTTask",
                                                    string.Format("Preparing to delete {0} files", listOfFiles.Count()),
                                                    string.Empty, 0, ref _refire);

                    int fileCounter = 0;

                    foreach (var file in listOfFiles)
                    {
                        SftpChannel.rm(file);

                        ComponentEvents.FireInformation(0, "SSISSFTTask",
                                                        string.Format("File {0} deleted", file),
                                                        string.Empty, 0, ref _refire);

                        fileCounter++;
                    }

                    ComponentEvents.FireInformation(0, "SSISSFTTask",
                                                    string.Format("Total deleted files {0}", fileCounter),
                                                    string.Empty, 0, ref _refire);
                }
            }
            else if (filePath.Contains("*") || filePath.Contains("?"))
            {
                var patternList = SFTPTools.SFTPScanDirs(this, filePath, RecursiveDepth);

                ComponentEvents.FireInformation(0, "SSISSFTTask",
                                                string.Format("Number of files to delete {0}", patternList.Count),
                                                string.Empty, 0, ref _refire);

                int fileCounter = 0;

                foreach (var file in patternList)
                {
                    ComponentEvents.FireInformation(0, "SSISSFTTask", string.Format("Deleting file: {0}", file), string.Empty, 0, ref _refire);
                    SftpChannel.rm(file);

                    fileCounter++;
                }

                ComponentEvents.FireInformation(0, "SSISSFTTask", string.Format("Number of deleted files: {0}", fileCounter), string.Empty, 0, ref _refire);
            }
            else if (!RecordsetHandler.RecordsetEnabled && (!filePath.Contains("*") || !filePath.Contains("?")))
            {
                ComponentEvents.FireInformation(0, "SSISSFTTask",
                                                string.Format("Deleting file: {0}", filePath),
                                                string.Empty, 0, ref _refire);
                SftpChannel.rm(filePath);
            }
        }
Пример #2
0
        public override void Get(string fromFilePath, string toFilePath)
        {
            #region Recordset
            if (RecordsetHandler.RecordsetEnabled)
            {
                IEnumerable <string> listOfFiles = RecordsetHandler.GetValues();
                if (listOfFiles != null)
                {
                    ComponentEvents.FireInformation(0, "SSISSFTTask",
                                                    string.Format("Preparing to copy {0} files", listOfFiles.Count()),
                                                    string.Empty, 0, ref _refire);

                    int    fileCounter    = 0;
                    int    lastSlashIndex = fromFilePath.LastIndexOf('/');
                    string dir            = fromFilePath.Substring(0, lastSlashIndex + 1);

                    foreach (var file in listOfFiles)
                    {
                        string from = (dir.Length == 0)
                                         ? file
                                         : string.Format("{0}{1}", dir, file);

                        if (Directory.Exists(toFilePath))
                        {
                            toFilePath = (toFilePath[toFilePath.Length - 1] != '\\') ? toFilePath + "\\" : toFilePath;
                        }
                        else if (File.Exists(toFilePath))
                        {
                            toFilePath = string.Format("{0}\\", new FileInfo(toFilePath).Directory.FullName);
                        }

                        string to = string.Format("{0}{1}", toFilePath, file);

                        SftpChannel.get(from, to, m_monitor, ChannelSftp.OVERWRITE);

                        if (DeleteFileOnTransferCompleted)
                        {
                            Delete(from);
                        }

                        ComponentEvents.FireInformation(0, "SSISSFTTask",
                                                        string.Format("File copied from {0} to {1}", from, to),
                                                        string.Empty, 0, ref _refire);

                        fileCounter++;
                    }

                    ComponentEvents.FireInformation(0, "SSISSFTTask",
                                                    string.Format("Total copied files {0}", fileCounter),
                                                    string.Empty, 0, ref _refire);
                }
            }
            #endregion

            #region File Mask
            else if (fromFilePath.Contains("*") || fromFilePath.Contains("?"))
            {
                var patternedList = SFTPTools.SFTPScanDirs(this, fromFilePath, RecursiveDepth);
                int fileCounter   = 0;

                int lastBackSlashIndex = fromFilePath.LastIndexOf('/');

                string dir = fromFilePath.Substring(0, lastBackSlashIndex + 1);

                ComponentEvents.FireInformation(0, "SSISSFTTask",
                                                string.Format("Preparing to copy {0} files", patternedList.Count),
                                                string.Empty, 0, ref _refire);

                foreach (var file in patternedList)
                {
                    //if (Directory.Exists(toFilePath))
                    //{
                    //    toFilePath = (toFilePath[toFilePath.Length - 1] != '\\') ? toFilePath + "\\" : toFilePath;
                    //}
                    //else if (File.Exists(toFilePath))
                    //{
                    //    toFilePath = string.Format("{0}\\", new FileInfo(toFilePath).Directory.FullName);
                    //}

                    string to = string.Empty;

                    SFTPTools.CreateTreeFolderFromLocal(toFilePath, dir, file, ref to);

                    SftpChannel.get(file, to, m_monitor, ChannelSftp.OVERWRITE);
                    if (DeleteFileOnTransferCompleted)
                    {
                        Delete(file);
                    }

                    ComponentEvents.FireInformation(0, "SSISSFTTask",
                                                    string.Format("File copied from {0} to {1}", file, to),
                                                    string.Empty, 0, ref _refire);
                    fileCounter++;
                }

                ComponentEvents.FireInformation(0, "SSISSFTTask",
                                                string.Format("Total copied files {0}", fileCounter),
                                                string.Empty, 0, ref _refire);
            }
            #endregion

            #region File Only
            else if (!RecordsetHandler.RecordsetEnabled && (!fromFilePath.Contains("*") || !fromFilePath.Contains("?")))
            {
                SftpChannel.get(fromFilePath, toFilePath, m_monitor, ChannelSftp.OVERWRITE);
                if (DeleteFileOnTransferCompleted)
                {
                    Delete(fromFilePath);
                }
                ComponentEvents.FireInformation(0, "SSISSFTTask",
                                                string.Format("File copied from {0} to {1}: {0}", fromFilePath, toFilePath),
                                                string.Empty, 0, ref _refire);
            }
            #endregion
        }