Click here to Skip to main content
13,200,729 members (52,774 online)
Rate this:
Please Sign up or sign in to vote.
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

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()
            '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
            '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\"

'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
        Catch ex As Exception
            Dts.TaskResult = ScriptResults.Failure
        End Try
        Dts.TaskResult = ScriptResults.Success
    End Sub
Posted 20-Feb-13 3:11am
Updated 20-Feb-13 23:37pm
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

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Use something similar to the following to get the filename ...
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
Marcus Kramer 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171020.1 | Last Updated 20 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100