Hello JB,
I am new to programming, but below is the code I'm using. It works until a
large file (120MB) is downloaded. Once it downloads, no other files in the
directory are downloaded, and I get an error msg saying my connection timed
out.
Can you send me an example of what I should do based on my code below?
------------
'And we obtain our file(s):
ftp.ReceiveFiles(sbDownloadFiles.ToString().Substr ing(0, _
sbDownloadFiles.ToString.Length - 1).Split("|".ToCharArray()), _
Dts.Variables("FtpDestination").Value.ToString, True, False)
-------------
Also, do I need to set KeepAlive to True? I thought is defaulted to True.
Here is my code:
------------------------------------
Public Sub Main()
Dim ftp As FtpClientConnection
Dim retrieveFiles As Boolean = False
Dim ftpWeb As FtpWebRequest
Try
ftpWeb = CType(FtpWebRequest.Create("ftp://" +
Dts.Variables("FTPURL").Value.ToString + _
"/" + Dts.Variables("FTPDirectory").Value.ToString), FtpWebRequest)
ftpWeb.Credentials = New
NetworkCredential(Dts.Variables("FTPUser").Value.T oString,
Dts.Variables("FTPPassword").Value.ToString())
ftpWeb.Method = WebRequestMethods.Ftp.ListDirectoryDetails
'Using fileReader As StreamReader = File.OpenText(baseFileName)
Dim srResponse As New StreamReader(ftpWeb.GetResponse().GetResponseStrea m())
Dim readLine As String
Dim stringComponents() As String
Dim sbDownloadFiles As New StringBuilder()
Dim fileEnding As String = Dts.Variables("FtpFileEnding").Value.ToString
Dim ignoreDate As Boolean =
Convert.ToBoolean(Dts.Variables("IgnoreDate").Valu e.ToString)
While Not srResponse.EndOfStream()
readLine = srResponse.ReadLine()
If readLine.Trim().EndsWith(fileEnding) Then
stringComponents = readLine.Split(" ".ToCharArray())
'Since the file is updated at least once a month, we just check the day:
If ignoreDate Or Math.Abs(DateTime.Now.Day -
Int32.Parse(stringComponents(17))) < 2 Then
'This file has been modified within the last day or so...
retrieveFiles = True
sbDownloadFiles.Append(stringComponents(19) + "|")
End If
End If
End While
srResponse.Close()
srResponse = Nothing
ftpWeb = Nothing
If retrieveFiles Then
'Now we need to build our FTP connection:
Dim fiRemoteFile As FileInfo
Dim ftpConnectionManager As ConnectionManager
ftpConnectionManager = Dts.Connections.Add("FTP")
ftpConnectionManager.Properties("ServerName").SetV alue(ftpConnectionManager,
Dts.Variables("FTPURL").Value)
ftpConnectionManager.Properties("ServerPort").SetV alue(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").SetValu e(ftpConnectionManager,
Dts.Variables("FTPTimeout").Value)
ftpConnectionManager.Properties("ChunkSize").SetVa lue(ftpConnectionManager,
Dts.Variables("FtpChunkSize").Value)
ftpConnectionManager.Properties("Retries").SetValu e(ftpConnectionManager,
Dts.Variables("FTPRetries").Value)
ftp = New FtpClientConnection(ftpConnectionManager.AcquireCo nnection(Nothing))
'Next we connect to the ftp server
ftp.Connect()
ftp.SetWorkingDirectory(Dts.Variables("FTPDirector y").Value.ToString)
'And we obtain our file(s):
ftp.ReceiveFiles(sbDownloadFiles.ToString().Substr ing(0, _
sbDownloadFiles.ToString.Length - 1).Split("|".ToCharArray()), _
Dts.Variables("FtpDestination").Value.ToString, True, False)
End If
'If we did not download anything new there is nothing to process...
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
-------------------------------------
Thanks,
Jason
"J.B. Moreno" wrote:
In article <F1**********************************@microsoft.co m>, Jason
<ja*******@online.nospamwrote:
Hello, can someone please suggest to me how I can keep my ftp connection from
timing out after a large file download?
FTP downloads take place on two connections, most likely your command
connection is timing out for lack of use...you might give it a kick and
send it a command every once in a while.
--
J.B. Moreno