Click here to Skip to main content
Rate this: bad
good
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()
        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
 ftp.Close()
        Catch ex As Exception
            Dts.TaskResult = ScriptResults.Failure
        End Try
        Dts.TaskResult = ScriptResults.Success
 
    End Sub
Posted 20-Feb-13 4:11am
Edited 21-Feb-13 0:37am
v5
Comments
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
good
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
  Permalink  
Comments
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 Kornfeld Eliyahu Peter 275
1 Maciej Los 214
2 Sergey Alexandrovich Kryukov 200
3 King Fisher 185
4 OriginalGriff 163
0 OriginalGriff 6,223
1 DamithSL 4,724
2 Maciej Los 4,196
3 Kornfeld Eliyahu Peter 3,894
4 Sergey Alexandrovich Kryukov 3,496


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 20 Mar 2013
Copyright © CodeProject, 1999-2014
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