Beispiel #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);
            }
        }
Beispiel #2
0
        public override void Put(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;

                    foreach (var file in listOfFiles)
                    {
                        SftpChannel.put(file, toFilePath, m_monitor, ChannelSftp.OVERWRITE);
                        if (DeleteFileOnTransferCompleted)
                        {
                            File.Delete(file);
                        }

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

                        fileCounter++;
                    }

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

            #region FileMask
            else if (fromFilePath.Contains("*") || fromFilePath.Contains("?"))
            {
                int lastBackSlashIndex = fromFilePath.LastIndexOf('\\');

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

                var filePaths = new List <string>();

                DirectoryInfo initialDir = new DirectoryInfo(dir);


                SFTPTools.LocalScanDirs(initialDir, pattern, RecursiveCopy ? RecursiveDepth : 0, ref filePaths);

                int fileCounter = 0;

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

                foreach (var filePath in filePaths)
                {
                    string fileDestination = string.Empty;
                    SFTPTools.CreateTreeFolderFromSFTP(SftpChannel, toFilePath, dir, filePath, ref fileDestination);

                    /*string fileDestination = (toFilePath[toFilePath.Length - 1] == '/')
                     *                           ? toFilePath + fileInfo.Name
                     *                           : toFilePath + '/' + fileInfo.Name;*/

                    ComponentEvents.FireInformation(0, "SSISSFTTask",
                                                    string.Format("Send file from {0} to {1}", filePath, fileDestination),
                                                    string.Empty, 0, ref _refire);

                    SftpChannel.put(filePath,
                                    fileDestination,
                                    m_monitor,
                                    ChannelSftp.OVERWRITE);

                    if (DeleteFileOnTransferCompleted)
                    {
                        File.Delete(filePath);
                    }

                    fileCounter++;
                }

                ComponentEvents.FireInformation(0, "SSISSFTTask",
                                                string.Format("Number of sent files: {0}", fileCounter),
                                                string.Empty, 0, ref _refire);
            }
            #endregion

            #region Only the file
            else if (!RecordsetHandler.RecordsetEnabled && (!fromFilePath.Contains("*") || !fromFilePath.Contains("?")))
            {
                SftpChannel.put(fromFilePath, toFilePath, m_monitor, ChannelSftp.OVERWRITE);
                if (DeleteFileOnTransferCompleted)
                {
                    File.Delete(fromFilePath);
                }
                ComponentEvents.FireInformation(0, "SSISSFTTask",
                                                string.Format("File sent from {0} to {1}", fromFilePath, toFilePath),
                                                string.Empty, 0, ref _refire);
            }
            #endregion
        }
Beispiel #3
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
        }