Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, the code below works BUT only when i write the entire filename and .zip extension in the path (Bold & underlined section) and the problem im facing is that filenames somtimes change. so how do i get only .zip files without specifying the file name in a folder? Please help

VB
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime

<microsoft.sqlserver.dts.tasks.scripttask.ssisscripttaskentrypointattribute> _
<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()
        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, "\")
            cm.Properties("ServerUserName").SetValue(cm, "")
            cm.Properties("ServerPassword").SetValue(cm, "")
            cm.Properties("ServerPort").SetValue(cm, "")
            cm.Properties("Timeout").SetValue(cm, "0") 'The 0 setting will make it not timeout
            cm.Properties("ChunkSize").SetValue(cm, "1") '1000 kb
            cm.Properties("Retries").SetValue(cm, "")
            '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) As String

files(0) = "K:\SISS\file2.zip"

'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, "/FtpRainbow", True, False) ' the True makes it overwrite existing file and False is saying that it is not transferring ASCII
VB
ftp.Close()
       Catch ex As Exception
           Dts.TaskResult = ScriptResults.Failure
       End Try
       Dts.TaskResult = ScriptResults.Success

   End Sub
Posted
Updated 20-Feb-13 23:37pm
v5
Comments
phil.o 20-Feb-13 10:05am    
I hope the credentials that we can see in your code are wrong ; otherwise you may encounter some serious problems if someone badly intentioned decides to use them.
You should hide such details when you post on a forum.

1 solution

Use something similar to the following to get the filename ...
VB
Dim d As DirectoryInfo = New DirectoryInfo("c:\\")
Dim f As FileInfo() = d.GetFiles("*.zip")
files(0) = f(0).Name 'actually you don't need the files array just keeping your variable name for illustration
 
Share this answer
 
Comments
fjdiewornncalwe 20-Feb-13 14:14pm    
+5. Works for me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900