Advertisement

05.27.2008 at 01:57PM PDT, ID: 23436334
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.8

How to download copy of file ftom ftp site based on creation date

Asked by AJ_Jin in MS SQL DTS, SQL Server 2005

Tags:

Hello Everybody.
I recently got a request to develop SSIS package that downloads a copy of file from FTP server based on creation date.
I found an sample script code for the task from MSDN forum and modified a bit based on my environment (the modification was minor as i was doing for testing purpose.)

The modified code is posted below.

When I tried to execute the package holding script task with modified code, I got an runtime error saying that the package got an exception and also saying element could not be found in package.
I am suspecting some misconfiguration when I set values on variables.
I had to use wildcard when I set a value of FtpFileEnding variable cause the source file name contains date information and keep being changed based on crreation date. If I cannot use wildcard for variavle value? what i should to do?

I also wondering that ReceiveFiles method simply copies file from source not moving file.
(I am not used to use ftp so the question may sound too basic.)

Also, when I created the variables, I set string as type. Do I still need to add .ToString method when I create script variable using package variable?

I'm very new to develping SSIS package so any comments or suggestions will be appreciated.
And thank you all for your help and support in advanceStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
Imports System
Imports System.Data
Imports System.Math
Imports System.Net
Imports System.IO
Imports System.Text
Imports Microsoft.SqlServer.Dts.Runtime
 
Public Class ScriptMain
 
	' The execution engine calls this method when the task executes.
	' To access the object model, use the Dts object. Connections, variables, events,
	' and logging features are available as static members of the Dts class.
	' Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.
	' 
	' To open Code and Text Editor Help, press F1.
	' To open Object Browser, press Ctrl+Alt+J.
 
	Public Sub Main()
		'
		' Add your code here
        '
        Dim ftp As FtpClientConnection
        Dim retrieveFiles As Boolean = False
        Dim ftpWeb As FtpWebRequest
        Try
            ftpWeb = CType(FtpWebRequest.Create("ftp://" + Dts.Variables("FTPURL").Value.ToString), FtpWebRequest)
            ftpWeb.Credentials = New NetworkCredential(Dts.Variables("FTPUser").Value.ToString, Dts.Variables("FTPPassword").Value.ToString())
            ftpWeb.Method = WebRequestMethods.Ftp.ListDirectoryDetails
            Dim srResponse As New StreamReader(ftpWeb.GetResponse().GetResponseStream())
            Dim readLine As String
            Dim stringComponents() As String
            Dim sbDownloadFiles As New StringBuilder()
            Dim fileEnding As String = Dts.Variables("FtpFileEnding").Value.ToString
            While Not srResponse.EndOfStream()
                readLine = srResponse.ReadLine()
                If readLine.Trim().EndsWith(fileEnding) Then
                    stringComponents = readLine.Split(" ".ToCharArray())
                    If Math.Abs(DateTime.Now.Day - Int32.Parse(stringComponents(17))) < 2 Then
                        retrieveFiles = True
                        sbDownloadFiles.Append(stringComponents(19) + "|")
                    End If
                End If
            End While
            srResponse.Close()
            srResponse = Nothing
            If retrieveFiles Then
                Dim fiRemoteFile As FileInfo
                Dim ftpConnectionManager As ConnectionManager
                ftpConnectionManager = Dts.Connections.Add("FTP")
                ftpConnectionManager.Properties("ServerName").SetValue(ftpConnectionManager, Dts.Variables("FTPURL").Value)
                ftpConnectionManager.Properties("serverPort").SetValue(ftpConnectionManager, Dts.Variables("FTPPort").Value)
                ftpConnectionManager.Properties("ServerUserName").SetValue(ftpConnectionManager, Dts.Variables("FTPUser").Value)
                ftpConnectionManager.Properties("ServerPassword").SetValue(ftpConnectionManager, Dts.Variables("FTPPassword").Value)
                ftpConnectionManager.Properties("Timeout").SetValue(ftpConnectionManager, Dts.Variables("FTPTimeout").Value)
                ftpConnectionManager.Properties("ChunkSize").SetValue(ftpConnectionManager, Dts.Variables("FtpChunkSize").Value)
                ftpConnectionManager.Properties("Retries").SetValue(ftpConnectionManager, Dts.Variables("FTPRetries").Value)
                ftp = New FtpClientConnection(ftpConnectionManager.AcquireConnection(Nothing))
                ftp.Connect()
                ftp.ReceiveFiles(sbDownloadFiles.ToString().Substring(0, sbDownloadFiles.ToString.Length - 1).Split("|".ToCharArray()), Dts.Variables("FtpDestination").Value.ToString, True, False)
            End If
 
            Dts.Variables("ContinueProcessing").Value = retrieveFiles
            Dts.TaskResult = Dts.Results.Success
 
        Catch exError As Exception
            Throw exError
        Finally
            If Not ftpWeb Is Nothing Then
                ftpWeb = Nothing
            End If
            If Not ftp Is Nothing Then
                ftp.Close()
            End If
 
        End Try
 
 
	End Sub
 
End Class
[+][-]05.28.2008 at 01:05AM PDT, ID: 21658513

View this solution now by starting your 14-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: MS SQL DTS, SQL Server 2005
Tags: SSIS VB script
Sign Up Now!
Solution Provided By: nigelrivett
Participating Experts: 1
Solution Grade: A
 
 
[+][-]05.28.2008 at 10:11AM PDT, ID: 21662254

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.11.2008 at 03:25AM PDT, ID: 22448040

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 14-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]09.17.2008 at 04:33PM PDT, ID: 22504826

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 14-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-43 / EE_QW_2_20070628