My usual setup is a BR that connects to the SFTP, which assures everything related to the login is handled in a single point.
Make sure you include Imports WinSCP in the header.
Here's a sample code:
Imports System
Imports System.Data
Imports System.Data.Common
Imports System.IO
Imports System.Collections.Generic
Imports System.Globalization
Imports System.Linq
Imports Microsoft.VisualBasic
Imports System.Windows.Forms
Imports OneStream.Shared.Common
Imports OneStream.Shared.Wcf
Imports OneStream.Shared.Engine
Imports OneStream.Shared.Database
Imports OneStream.Stage.Engine
Imports OneStream.Stage.Database
Imports OneStream.Finance.Engine
Imports OneStream.Finance.Database
Imports WinSCP
Namespace OneStream.BusinessRule.Extender.SFTP
Public Class MainClass
Public Shared Function SFTPConnection() As SessionOptions
Dim SessionOpts As New SessionOptions
With SessionOpts
.Protocol = WinSCP.Protocol.Sftp
.Portnumber = 22
.HostName = "ftp.XXXXX.XXXXX"
.UserName = "SFTPXXXXX"
.Password ="XXXXXX"
.GiveUpSecurityAndAcceptAnySshHostKey = true
End With
Return SessionOpts
End Function
End Class
End Namespace
Then on my other BR, I'd instantiate that rule and open the connection as usual.
Dim sftpHelper As New OneStream.BusinessRule.Extender.SFTP.MainClass()
Dim FileFound As Boolean = False
Using session As New Session
' Connect
session.Open(sftpHelper.SFTPConnection())
....
If you want to do something similar, make sure to reference the connection BR in your Referenced Assemblies.