Skip to main content
October 5, 2022

Business Rule for SFTP

  • October 5, 2022
  • 4 replies
  • 0 views

Hi - we're trying to PULL files from an SFTP server. These will be used for our OneStream load.

Are there any sample BRs that we can reference to facilitate the file transfer from the SFTP server to OneStream? Are there libraries readily available in OS for this?

 


So far, we have completed the following.

1. Whitelisting of OS IP from SFTP Server

2. Received SFTP server and credentials needed

 

Thanks!

4 replies

October 5, 2022

Hi there!
I have not done this for a while, but I remember that you need to contact OneStream support to install winscp.dll from there you will be able to use FTP.
Then in your BR do not forget to add 

'Imports
Imports WinSCP '<--- WinSCPnet assembly is required on the server

And get all your info from there

 

https://winscp.net/eng/docs/library#:~:text=The%20WinSCP%20.,S3%20and%20SCP%20sessions%20from%20.

Cheers

October 5, 2022

https://winscp.net/eng/docs/library#vbnet

 

Imports WinSCP
 
Friend Class Example
 
    Public Shared Function Main() As Integer
 
        Try
            ' Setup session options
            Dim sessionOptions As New SessionOptions
            With sessionOptions
                .Protocol = Protocol.Sftp
                .HostName = "example.com"
                .UserName = "user"
                .Password = "mypassword"
                .SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx..."
            End With
 
            Using session As New Session
                ' Connect
                session.Open(sessionOptions)
 
                ' Upload files
                Dim transferOptions As New TransferOptions
                transferOptions.TransferMode = TransferMode.Binary
 
                Dim transferResult As TransferOperationResult
                transferResult =
                    session.PutFiles("d:\toupload\*", "/home/user/", False, transferOptions)
 
                ' Throw on any error
                transferResult.Check()
 
                ' Print results
                For Each transfer In transferResult.Transfers
                    Console.WriteLine("Upload of {0} succeeded", transfer.FileName)
                Next
            End Using
 
            Return 0
        Catch e As Exception
            Console.WriteLine("Error: {0}", e)
            Return 1
        End Try
 
    End Function
 
End Class
February 2, 2023

What type of business Rule did you use, I don't see namespace there.

Thanks

February 8, 2023

Hi Tom, It was  extender BR. Do not forget to reference it your assemblies... (I have done that a while ago)

February 7, 2025

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.

 

February 8, 2025

Sorry, but I really would not recommend that anymore. Not in version of OS8.2+ as it is deprecated. OS is not using WinSCP dlls anymore.
Instead the right approach is to use Renci dlls. (https://github.com/sshnet/SSH.NET)
Please revert to OS documentation too, page 87 : https://documentation.onestream.com/1388457/Content/PDFs/Smart_Integration_Connector_Guide.pdf
Cheers

February 8, 2025

Hey Nicolas, that's really helpful info! It's been a while since I’ve dealt with anything SFTP-related. Thanks for the heads-up!