Advertisement
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.
Your Input Matters 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! |
||
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
|