private void EnsureSFTPConnection() { if (!IsConnected) { throw new Exception("Can't use SFTP if not connected"); } if (Sftp == null || !Sftp.IsConnected) { Sftp = new SFTPConnection(m_conn); Sftp.StartSFTPSession(); } }
public void Disconnect() { if (m_conn == null) { return; } try { m_conn.Disconnect(""); } // ignore these catch (SocketException) { } catch (ObjectDisposedException) { } m_conn = null; Sftp = null; m_shells.Clear(); }
public async Task <List <SFTPFile> > GetFilesList([ActivityTrigger] SFTPConnection fTPConnectionInfo) { await Task.Delay(2000); var list = new List <SFTPFile> { new SFTPFile { Name = "file1.json", Content = "" }, new SFTPFile { Name = "file2.json", Content = "" }, new SFTPFile { Name = "file3.json", Content = "" }, new SFTPFile { Name = "file4.json", Content = "" }, new SFTPFile { Name = "file5.json", Content = "" }, new SFTPFile { Name = "file6.json", Content = "" }, new SFTPFile { Name = "file7.json", Content = "" }, new SFTPFile { Name = "file8.json", Content = "" }, new SFTPFile { Name = "file9.json", Content = "" } }; return(list); }
public static async Task <List <string> > RunOrchestrator( [OrchestrationTrigger] IDurableOrchestrationContext context ) { var outputLogs = new List <string>(); // Integration Flow // 1- Get Secure Info From KeyVault var keyvaultKey = "company-ftp-information-key"; FTPConnectionInfo sftpConnectionInfo = await context.CallActivityAsync <FTPConnectionInfo>("GetFTPInfoFromVault", keyvaultKey); outputLogs.Add("SFTP Connection Info Fetched Successfully From Keyvault"); // 2- Connect to FTP Client SFTPConnection ftpConnection = await context.CallActivityAsync <SFTPConnection>("SFTPGetConnection", sftpConnectionInfo); outputLogs.Add("SFTP Connected Successfully"); // 3- Fetch List of Files From SFTP ftpConnection.Directory = "client/directory/path"; List <SFTPFile> filesList = await context.CallActivityAsync <List <SFTPFile> >("SFTPGetFilesList", ftpConnection); outputLogs.Add("SFTP Files List Fetched Successfully"); // 4- Start Processing Files List <string> filesImportLogs = await context.CallSubOrchestratorAsync <List <string> >("EMG_FilesProcessor", filesList); outputLogs.AddRange(filesImportLogs); outputLogs.Add($"{filesImportLogs.Count} SFTP Files Processed Successfully"); return(outputLogs); }
/// <summary> /// Executes the action based on seleted options. /// </summary> /// <param name="connections">The connections.</param> /// <param name="variableDispenser">The variable dispenser.</param> /// <param name="componentEvents">The component events.</param> /// <param name="log">The log.</param> /// <param name="transaction">The transaction.</param> /// <returns></returns> /// <exception cref="System.Exception">Data Set Variable Must Contain a Valid List<ISFTPFileInfo> Object.</exception> public override DTSExecResult Execute(Connections connections, VariableDispenser variableDispenser, IDTSComponentEvents componentEvents, IDTSLogging log, object transaction) { try { bool fireAgain = true; string _localFile = Common.GetVariableValue <string>(this.localFile, variableDispenser); string _remoteFile = Common.GetVariableValue <string>(this.remoteFile, variableDispenser); string _hostName = Common.GetVariableValue <string>(this.hostName, variableDispenser); int _portNumber = Common.GetVariableValue <int>(this.portNumber, variableDispenser); string _userName = Common.GetVariableValue <string>(this.userName, variableDispenser); string _passWord = Common.GetVariableValue <string>(this.passWord, variableDispenser); string _fileFilter = Common.GetVariableValue <string>(this.fileFilter, variableDispenser); List <ISFTPFileInfo> sftpFileInfo = new List <ISFTPFileInfo>(); SFTPConnection sftp = new SFTPConnection(_hostName, _userName, _passWord, _portNumber, this.stopOnFailure, componentEvents, this.logLevel); if (this.fileAction == SFTPFileAction.ReceiveMultiple || this.fileAction == SFTPFileAction.SendMultiple) { if (Common.GetVariableValue <object>(fileInfo, variableDispenser).GetType() != typeof(List <ISFTPFileInfo>)) { throw new Exception("Data Set Variable Must Contain a Valid List<ISFTPFileInfo> Object."); } } if (this.fileAction == SFTPFileAction.Send) { List <string> fileList = Common.GetFileList(_localFile, _fileFilter, this.isRecursive); foreach (string fileName in fileList) { sftpFileInfo.Add(new SFTPFileInfo(fileName, _remoteFile, this.overwriteDest, this.removeSource)); } if (sftpFileInfo.Count > 0) { sftp.UploadFiles(sftpFileInfo); } else { componentEvents.FireInformation(1, "", "No files selected for Upload.", "", 1, ref fireAgain); } } else if (this.fileAction == SFTPFileAction.SendMultiple) { sftpFileInfo = (List <ISFTPFileInfo>)Common.GetVariableValue <object>(fileInfo, variableDispenser); if (sftpFileInfo.Count > 0) { sftp.UploadFiles(sftpFileInfo); } else { componentEvents.FireInformation(1, "", "No files selected for Upload.", "", 1, ref fireAgain); } } else if (this.fileAction == SFTPFileAction.Receive) { List <IRemoteFileInfo> remoteFileList = sftp.ListFiles(_remoteFile); remoteFileList = Common.GetRemoteFileList(remoteFileList, _fileFilter); foreach (IRemoteFileInfo remoteFile in remoteFileList) { sftpFileInfo.Add(new SFTPFileInfo(_localFile, remoteFile.FullName, this.overwriteDest, this.removeSource)); } if (sftpFileInfo.Count > 0) { sftp.DownloadFiles(sftpFileInfo); } else { componentEvents.FireInformation(1, "", "No files selected for Download.", "", 1, ref fireAgain); } } else if (this.fileAction == SFTPFileAction.ReceiveMultiple) { sftpFileInfo = (List <ISFTPFileInfo>)Common.GetVariableValue <object>(fileInfo, variableDispenser); if (sftpFileInfo.Count > 0) { sftp.DownloadFiles(sftpFileInfo); } else { componentEvents.FireInformation(1, "", "No files selected for Download.", "", 1, ref fireAgain); } } else if (this.fileAction == SFTPFileAction.List) { List <IRemoteFileInfo> remoteFileList = sftp.ListFiles(_remoteFile); Common.SetVariableValue(this.remoteFileListVariable, remoteFileList, variableDispenser); } } catch (Exception ex) { componentEvents.FireError(0, "Execute: ", ex.Message + Environment.NewLine + ex.StackTrace, "", 0); return(DTSExecResult.Failure); } return(DTSExecResult.Success); }