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

SSIS Script task that FTP's files

$
0
0

I could not find the exact details on how to create a SSIS script that would ftp files on these forums, so I am adding my code to help save time for anyone else that might be wanting to do something similar.  Here is the VB code for my script task to FTP files (hope this helps someone):

' Microsoft SQL Server Integration Services Script Task

' Write scripts using Microsoft Visual Basic

' The ScriptMain class is the entry point of the Script Task.

Imports

System

Imports

System.Data

Imports

System.Math

Imports

Microsoft.SqlServer.Dts.Runtime

Public

Class ScriptMain

PublicSub Main()

Try

'Create the connection to the ftp server

Dim cm As ConnectionManager = Dts.Connections.Add("FTP")

'Set the properties like username & password

cm.Properties(

"ServerName").SetValue(cm, "Enter your Server Name here")

cm.Properties(

"ServerUserName").SetValue(cm, "Enter your FTP User Name here")

cm.Properties(

"ServerPassword").SetValue(cm, "Enter your FTP Password here")

cm.Properties(

"ServerPort").SetValue(cm, "21")

cm.Properties(

"Timeout").SetValue(cm, "0") 'The 0 setting will make it not timeout

cm.Properties(

"ChunkSize").SetValue(cm, "1000") '1000 kb

cm.Properties(

"Retries").SetValue(cm, "1")

'create the FTP object that sends the files and pass it the connection created above.

Dim ftp As FtpClientConnection = New FtpClientConnection(cm.AcquireConnection(Nothing))

'Connects to the ftp server

ftp.Connect()

'Build a array of all the file names that is going to be FTP'ed (in this case only one file)

Dim files(0) AsString

files(0) =

"Drive:\FullPath\YourFileName"

'ftp the file

'Note: I had a hard time finding the remote path directory. I found it by mistake by creating both the FTP connection and task in the SSIS package and it defaulted the remote path setting in the FTP task.

ftp.SendFiles(files,

"/Enter Your Remote Path", True, False) ' the True makes it overwrite existing file and False is saying that it is not transferring ASCII

ftp.Close()

Catch ex As Exception

Dts.TaskResult = Dts.Results.Failure

EndTry

Dts.TaskResult = Dts.Results.Success

 

EndSub

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>