go to child directory using FTP task
I am using the FTP task successfully as follows to connect to the server and give it the login details i.e.
servername: servername.companyname.com
username: username
password: pwd
Now I would like to get to another directory in that server i.e.
servername.companyname.com/data/today
If I enter this servername with the directries then it fails connection.
Question:
How can I go to another directory once I have established connection in FTP task?
Thanks
March 22nd, 2012 7:28am
I guess you can alternatively try using a Script: I pasted here from one of the old script I had, below one will list all the files from a ftp directory. You can use it to alter anyways. In your case, var_WorkDirector just set: "/data/today" also if
required you can dynamically generate that too. All the user variable below are almost set explainatory so u can get those.
=======================================================================================
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.Collections.Generic
<System.AddIn.AddIn("ScriptMain", Version:="1.0", Publisher:="", Description:="")> _
<System.CLSCompliantAttribute(False)> _
Partial Public Class ScriptMain
Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
Enum ScriptResults
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
End Enum
Public Sub Main()
Dim cmFTP As ConnectionManager = Dts.Connections("conn_FileSource(FTP)")
cmFTP.Properties("ServerName").SetValue(cmFTP, Dts.Variables("var_ftppath").Value)
cmFTP.Properties("ServerUserName").SetValue(cmFTP, Dts.Variables("var_ftpuser").Value)
cmFTP.Properties("ServerPassword").SetValue(cmFTP, Dts.Variables("var_ftppassword").Value)
cmFTP.Properties("ServerPort").SetValue(cmFTP, Dts.Variables("var_ftpport").Value)
Dim FtpCC As FtpClientConnection = New FtpClientConnection(cmFTP.AcquireConnection(Nothing))
FtpCC.Connect()
FtpCC.SetWorkingDirectory(Dts.Variables("var_workdirectory").Value)
Dim saFileNames() As String = Nothing
Dim FilteredFiles As New List(Of String)
Dim saFolderNames() As String = Nothing
FtpCC.GetListing(saFolderNames, saFileNames)
If Not saFileNames Is Nothing Then
For Each sFileName As String In saFileNames
FilteredFiles.Add(sFileName)
Next
End If
Dts.Variables("var_FileCount").Value = FilteredFiles.Count()
FilteredFiles.Sort()
Dts.Variables("var_ftpfileslist").Value = FilteredFiles
FtpCC.Close()
Dts.TaskResult = ScriptResults.Success
End Sub
End Class
=========================================================================================Regards, Avik M.
Free Windows Admin Tool Kit Click here and download it now
March 22nd, 2012 7:46am
I guess you can alternatively try using a Script: I pasted here from one of the old script I had, below one will list all the files from a ftp directory. You can use it to alter anyways. In your case, var_WorkDirector just set: "/data/today" also if
required you can dynamically generate that too. All the user variable below are almost set explainatory so u can get those.
=======================================================================================
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.Collections.Generic
<System.AddIn.AddIn("ScriptMain", Version:="1.0", Publisher:="", Description:="")> _
<System.CLSCompliantAttribute(False)> _
Partial Public Class ScriptMain
Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
Enum ScriptResults
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
End Enum
Public Sub Main()
Dim cmFTP As ConnectionManager = Dts.Connections("conn_FileSource(FTP)")
cmFTP.Properties("ServerName").SetValue(cmFTP, Dts.Variables("var_ftppath").Value)
cmFTP.Properties("ServerUserName").SetValue(cmFTP, Dts.Variables("var_ftpuser").Value)
cmFTP.Properties("ServerPassword").SetValue(cmFTP, Dts.Variables("var_ftppassword").Value)
cmFTP.Properties("ServerPort").SetValue(cmFTP, Dts.Variables("var_ftpport").Value)
Dim FtpCC As FtpClientConnection = New FtpClientConnection(cmFTP.AcquireConnection(Nothing))
FtpCC.Connect()
FtpCC.SetWorkingDirectory(Dts.Variables("var_workdirectory").Value)
Dim saFileNames() As String = Nothing
Dim FilteredFiles As New List(Of String)
Dim saFolderNames() As String = Nothing
FtpCC.GetListing(saFolderNames, saFileNames)
If Not saFileNames Is Nothing Then
For Each sFileName As String In saFileNames
FilteredFiles.Add(sFileName)
Next
End If
Dts.Variables("var_FileCount").Value = FilteredFiles.Count()
FilteredFiles.Sort()
Dts.Variables("var_ftpfileslist").Value = FilteredFiles
FtpCC.Close()
Dts.TaskResult = ScriptResults.Success
End Sub
End Class
=========================================================================================Regards, Avik M.
March 22nd, 2012 2:27pm