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.ReceiveFile s(sbDownloadFil es.ToString().S ubstring(0, _
sbDownloadFiles .ToString.Lengt h - 1).Split("|".To CharArray()), _
Dts.Variables(" FtpDestination" ).Value.ToStrin g, 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 FtpClientConnec tion
Dim retrieveFiles As Boolean = False
Dim ftpWeb As FtpWebRequest
Try
ftpWeb = CType(FtpWebReq uest.Create("ft p://" +
Dts.Variables(" FTPURL").Value. ToString + _
"/" + Dts.Variables(" FTPDirectory"). Value.ToString) , FtpWebRequest)
ftpWeb.Credenti als = New
NetworkCredenti al(Dts.Variable s("FTPUser").Va lue.ToString,
Dts.Variables(" FTPPassword").V alue.ToString() )
ftpWeb.Method = WebRequestMetho ds.Ftp.ListDire ctoryDetails
'Using fileReader As StreamReader = File.OpenText(b aseFileName)
Dim srResponse As New StreamReader(ft pWeb.GetRespons e().GetResponse Stream())
Dim readLine As String
Dim stringComponent s() As String
Dim sbDownloadFiles As New StringBuilder()
Dim fileEnding As String = Dts.Variables(" FtpFileEnding") .Value.ToString
Dim ignoreDate As Boolean =
Convert.ToBoole an(Dts.Variable s("IgnoreDate") .Value.ToString )
While Not srResponse.EndO fStream()
readLine = srResponse.Read Line()
If readLine.Trim() .EndsWith(fileE nding) Then
stringComponent s = readLine.Split( " ".ToCharArray() )
'Since the file is updated at least once a month, we just check the day:
If ignoreDate Or Math.Abs(DateTi me.Now.Day -
Int32.Parse(str ingComponents(1 7))) < 2 Then
'This file has been modified within the last day or so...
retrieveFiles = True
sbDownloadFiles .Append(stringC omponents(19) + "|")
End If
End If
End While
srResponse.Clos e()
srResponse = Nothing
ftpWeb = Nothing
If retrieveFiles Then
'Now we need to build our FTP connection:
Dim fiRemoteFile As FileInfo
Dim ftpConnectionMa nager As ConnectionManag er
ftpConnectionMa nager = Dts.Connections .Add("FTP")
ftpConnectionMa nager.Propertie s("ServerName") .SetValue(ftpCo nnectionManager ,
Dts.Variables(" FTPURL").Value)
ftpConnectionMa nager.Propertie s("ServerPort") .SetValue(ftpCo nnectionManager ,
Dts.Variables(" FTPPort").Value )
ftpConnectionMa nager.Propertie s("ServerUserNa me").SetValue(f tpConnectionMan ager, Dts.Variables(" FTPUser").Value )
ftpConnectionMa nager.Propertie s("ServerPasswo rd").SetValue(f tpConnectionMan ager, Dts.Variables(" FTPPassword").V alue)
ftpConnectionMa nager.Propertie s("Timeout").Se tValue(ftpConne ctionManager,
Dts.Variables(" FTPTimeout").Va lue)
ftpConnectionMa nager.Propertie s("ChunkSize"). SetValue(ftpCon nectionManager,
Dts.Variables(" FtpChunkSize"). Value)
ftpConnectionMa nager.Propertie s("Retries").Se tValue(ftpConne ctionManager,
Dts.Variables(" FTPRetries").Va lue)
ftp = New FtpClientConnec tion(ftpConnect ionManager.Acqu ireConnection(N othing))
'Next we connect to the ftp server
ftp.Connect()
ftp.SetWorkingD irectory(Dts.Va riables("FTPDir ectory").Value. ToString)
'And we obtain our file(s):
ftp.ReceiveFile s(sbDownloadFil es.ToString().S ubstring(0, _
sbDownloadFiles .ToString.Lengt h - 1).Split("|".To CharArray()), _
Dts.Variables(" FtpDestination" ).Value.ToStrin g, True, False)
End If
'If we did not download anything new there is nothing to process...
Dts.Variables(" ContinueProcess ing").Value = retrieveFiles
Dts.TaskResult = Dts.Results.Suc cess
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************ *************** *******@microso ft.com>, Jason
<ja*******@onli ne.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