Click here to Skip to main content
11,718,289 members (89,468 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: VB.NET DTS
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
Edited 20-Feb-13 23:37pm
phil.o at 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 at 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
0 OriginalGriff 215
1 F-ES Sitecore 210
2 Maciej Los 140
3 Jochen Arndt 120
4 Andy Lanng 115
0 OriginalGriff 535
1 Maciej Los 529
2 Richard MacCutchan 440
3 CHill60 415
4 F-ES Sitecore 415

Advertise | Privacy | Mobile
Web01 | 2.8.150901.1 | Last Updated 20 Mar 2013
Copyright © CodeProject, 1999-2015
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