Forum Discussion
Hello!
Great question; WinSCP, indicated by the name, has dependencies on Windows which will unlikely be used in as an underpinning operating system in future releases as some context as to the why.
We have some details and examples on how to use the SSH.NET library outlined in the 8.5 SIC connector guide (Use Smart Integration Connector) with a simple example below.
The libraries are quite similar.
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Globalization;
using System.IO;
using System.Linq;
using Microsoft.CSharp;
using OneStream.Finance.Database;
using OneStream.Finance.Engine;
using OneStream.Shared.Common;
using OneStream.Shared.Database;
using OneStream.Shared.Engine;
using OneStream.Shared.Wcf;
using OneStream.Stage.Database;
using OneStream.Stage.Engine;
using Renci.SshNet;
namespace OneStream.BusinessRule.Extender.SFTP_SSH_C
{
public class MainClass
{
public object Main(SessionInfo si, BRGlobals globals, object api, ExtenderArgs args)
{
try
{
// --------------------------------------------------
// SSH.NET EXAMPLES
// --------------------------------------------------
// Setup SSH.NET session options from values in Cloud Administration Tools (CAT) Key Management - Secrets
var username = BRApi.Utilities.GetSecretValue(si, "SFTP-UserName");
var password = BRApi.Utilities.GetSecretValue(si, "SFTP-Password");
var authenticationMethod = new PasswordAuthenticationMethod(username, password);
var connectionInfo = new ConnectionInfo("52.151.252.48", username, authenticationMethod);
// Get the filepath - BatchHarvest in this example is File Share / Applications / GolfStreamDemo_v36 / Batch / Harvest
var fileDNpath = BRApi.Utilities.GetFileShareFolder(si, FileShareFolderTypes.BatchHarvest, null);
var fileSFTPpath = Path.Combine(fileDNpath, "SFTP_TEST_DOWNLOAD_" + DateTime.UtcNow.ToString("MM-dd-yyyy-HHmmss") + ".txt");
var fileSCPpath = Path.Combine(fileDNpath, "SCP_TEST_DOWNLOAD_" + DateTime.UtcNow.ToString("MM-dd-yyyy-HHmmss") + ".txt");
// SFTP Example
using (var sftpClient = new SftpClient(connectionInfo))
{
sftpClient.Connect();
using (var downloadStream = new FileStream(fileSFTPpath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))
{
sftpClient.DownloadFile("SFTP_TEST_DOWNLOAD.txt", downloadStream);
}
}
// SCP Example
using (var scpClient = new ScpClient(connectionInfo))
{
scpClient.Connect();
scpClient.Download("SFTP_TEST_DOWNLOAD.txt", new FileInfo(fileSCPpath));
}
return null;
}
catch (Exception ex)
{
throw ErrorHandler.LogWrite(si, new XFException(si, ex));
}
}
}
}
Related Content
- 7 months ago
- 3 years ago
- 3 years ago