Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

FTP object reference not set to an instance....

$
0
0

Hi,

This is what I am trying to do...I am trying to get listing from an FTP server and go to a folder and then I want to see if the folder is empty or it contains files.  How do I do that inVb.net?

 

Please note that I amnot allowed to bring the files to a directory(meaning, I cannot use a receive command and load it to a local directory).  I have to read the folder from the FTP directory itself and see if the folder  is empty or not. I don't get any error if files are available and it works fine.  Please help me!!! Thanks

I am getting an error at


myFtpConnection.GetListing(folderNames, fileNames) as "object reference not set to an instance of an object"


Public Sub Main()

Try
' Get the ftp connection from the Connection Managers collection
Dim ftpServer As ConnectionManager = Dts.Connections("myFtpServer")
' Create a FTP connection object and us the credentials of connection manager
Dim myFtpConnection As FtpClientConnection = New FtpClientConnection(ftpServer.AcquireConnection(Nothing))
myFtpConnection.ServerName = Dts.Variables("IPAddress").Value
myFtpConnection.ServerPassword = Dts.Variables("Password").Value
myFtpConnection.ServerPort = Dts.Variables("Port").Value
myFtpConnection.ServerUserName = Dts.Variables("UserName").Value

myFtpConnection.Connect()
 
Dts.Variables("IsSuccess").Value = 1
 
' MessageBox.Show(Dts.Variables("FtpWorkingDirectory").Value.ToString())
' Set work folder with the value of the variable
myFtpConnection.SetWorkingDirectory(Dts.Variables("FtpWorkingDirectory").Value.ToString())
MessageBox.Show(Dts.Variables("FtpWorkingDirectory").Value.ToString())
' Create StringArrays for filenames and folders
' The folderNames aren't used, but is mandatory
' for the next method.
Dim fileNames() As String
Dim folderNames() As String
Dim filecount As Integer
Dim fileNames() As String
Dim folderNames() As String
Dim filecount As Integer
 
' Get a directory listing and fill the StringArray variables

myFtpConnection.GetListing(folderNames, fileNames)
 

'For Each fileName In folderNames
' filecount = filecount + 1
'Next
For Each filename In fileNames
filecount = filecount + 1
Next
MessageBox.Show(filecount)
' Copy StringArray to ArrayList to fit in Object variable
Dim fileNamesArray As ArrayList = New ArrayList(fileNames)
' Optional sorter
fileNamesArray.Sort()
' Fill ssis object variable
Dts.Variables("FtpFileList").Value = fileNamesArray
' Close connection
myFtpConnection.Close()
' Close Script Task, set result to success
' Dts.Variables("IsSuccess").Value = 1
Dts.TaskResult = ScriptResults.Success
Catch ex As Exception
MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButtons.OK)
If ex.Message = "Exception from HRESULT: 0xC001602A" Then
Dts.Variables("IsSuccess").Value = 0
End If
'Dts.Events.FireError(1, ex.TargetSite.ToString(), ex.Message.ToString(), "", 0)
'Dts.TaskResult = ScriptResults.Failure
End Try
End Sub

End Class

Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>