Protected Function GetFTPFile(ByVal FileDaScaricare As String) As String
Dim r As String = String.Empty
Dim a As String = Now.Year
Dim m As String = Now.Month
If CInt(m) < 10 Then m = "0" & m
Dim d As String = Now.Day
If CInt(d) < 10 Then d = "0" & d
Dim f As String = "File da scaricare" & a & m & d
Try
Dim cm As ConnectionManager = Dts.Connections.Add("FTP")
cm.Properties("ServerName").SetValue("server ftp")
cm.Properties("ServerUserName").SetValue("username")
cm.Properties("ServerPassword").SetValue("password")
cm.Properties("ServerPort").SetValue(cm, "21")
cm.Properties("Timeout").SetValue(cm, "60") 'Se messo a 0 non si avrà timeout
cm.Properties("ChunkSize").SetValue(cm, "1000") '1000 kb
cm.Properties("Retries").SetValue(cm, "1")
Dim ftp As FtpClientConnection = New FtpClientConnection(cm.AcquireConnection(Nothing))
ftp.Connect()
ftp.SetWorkingDirectory("path directory remota")
Dim folders(0) As String
Dim files(0) As String
Dim fs(0) As String
ftp.GetListing(folders, files)
For Each FileName In files
If FileName.Contains(f) Then
If FileName.Contains(FileDaScaricare) Then
fs(0) = FileName
If FileName.Contains(fs(0)) Then
ftp.ReceiveFiles(fs, "path directory locale", True, True)
r = "File scaricato con successo"
Else
r = "File non trovato"
End If
End If
Else
r = "Nessun file trovato"
End If
Next
ftp.Close()
Catch ex As Exception
r = "Errore: " & ex.Message
End Try
Return r
End Function