Forum Discussion

YanSavinsky's avatar
YanSavinsky
New Contributor III
3 days ago

Files manipulation on SFTP Location

I need to move some files around the various folders on our SFTP server and I am trying to do it via the Extender BR. Basically I need to move the files from the staging folder into various other folders based on the file names.

The rule below compiles successfully. When executed, I get the exception on the second pass ("Chase" related) but no files are being moved anywhere.

I am stumped at the moment and would appreciate any suggestions.

Thank you in advance.

Yan

 

Public Class MainClass
		Public Function Main(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As ExtenderArgs) As Object
		Try
			
			'Set up SFTP connection session options
			Dim sessionOptions As New sessionOptions
			With sessionOptions
				.Protocol = Protocol.Sftp
			        .HostName = "xxxxxxxxxx.xxxxx.com"				
				.UserName = "XXXXXXX"
				.Password = "xxxXXxxxXXXXXx"
				.SshHostKeyFingerprint = "ssh-rsaxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxpNuL5H42WiDJY="
			End With
			
			'Use Session
			Using session As New Session
			
			'Connect
			session.Open(sessionOptions)
			
			Dim transferOptions As New TransferOptions
			transferOptions.TransferMode = TransferMode.Binary
			Dim baiDirLocation As String = session.HomePath & "/test/TXM/BAI/"
			Dim remoteFiles As RemoteDirectoryInfo = session.ListDirectory(baiDirLocation)
			Dim results As TransferOperationResult
			Dim fileNumber As Integer = 0
			
			For Each x As RemoteFileInfo In remoteFiles.Files
				
				Dim newName As String = Nothing
				
				If x.Name.Contains("Mizuho") Then
					results = session.PutFiles(baiDirLocation & x.Name, baiDirLocation & "Mizuho/" & x.Name, False, TransferOptions)

					If Not results.IsSuccess Then
						Throw New Exception("The file transfer from SFTP to OneStream harvest failed 1.")
					End If

				ElseIf x.Name.Contains("Chase") Then
					results = session.PutFiles(baiDirLocation & x.Name, baiDirLocation & "Chase/" & x.Name, False, TransferOptions)

					If Not results.IsSuccess Then
						Throw New Exception("The file transfer from SFTP to OneStream harvest failed 2.")
					End If
					'Nothing
				End If
				
					

					
				
					'Move or Remove Files or Move SFTP files to archive
					'Session.RemoveFiles(glDirLocation & "S4iiisubdata_US50.txt")

				fileNumber += 1
				
			Next
			'Next Ends the Loop
			End Using
			
			'Setup email distribution list When files are present
			Dim distributionList As New List(Of String)
			distributionList.Add("yan.savinsky@itochu.com,jin.yong@itochu.com")
			
			'Calls email Sub Routine
			'EmailNotification(batchinfo, si, distributionList)
			
			Return Nothing
			Catch ex As Exception
				Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
				
		End Try
		End Function
		
		
End Class

 

No RepliesBe the first to reply