Hi,
I have a folder in my FTP server where there are 10-15 files. How can I download specific pattern files from FTP. I need just 2 files out of 10
File names as
1. ABC Users-20160315T233101.csv
2. ABC - Workflow - Daily Update-2016-03-07-22-30-06.csv
P.S-> I am very beginner in VB (have to do in script task)
Till now , the code i am using(below) is running only when i am passing full file name from database table in FTP pattern (which is not correct) like ABC - Workflow - Daily Update-2016-03-07-22-30-06.csv
# My working Code
all variables taking values from database table and i am using script task in for each loop
Dim FTP_Path As String = Dts.Variables("User::lvar_File_Source_Path").Value.ToString
Dim FTP_UserName As String = Dts.Variables("User::lvar_FTP_UserName").Value.ToString
Dim FTP_Password As String = Dts.Variables("User::lvar_FTP_Password").Value.ToString
Dim FTP_In_Path As String = New_Dir
Dim File_Pattern As String = "/" + Dts.Variables("User::lvar_File_Source_Pattern").Value.ToString
FTPCopy(FTP_Path, FTP_UserName, FTP_Password, FTP_Pattern, File_Pattern, FTP_In_Path)
Function
' This Function is used to downlaod files from FTP
Public Sub FTPCopy(FTP_Path As String, FTP_UserName As String, FTP_Password As String, FTP_Pattern As String, File_Pattern As String, FTP_In_Path As String)
'Setting URL Properties
Dim URI As String = FTP_Path & FTP_Pattern
Dim ftp As System.Net.FtpWebRequest = _
CType(FtpWebRequest.Create(URI), FtpWebRequest)
'Setting FTP credentials
ftp.Credentials = New _
System.Net.NetworkCredential(FTP_UserName, FTP_Password)
'Settings and action
ftp.KeepAlive = False
'we want a binary transfer, not textual data
ftp.UseBinary = True
'downloading FTP File
ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile
'Get the response to the Ftp request and the associated stream
Using response As System.Net.FtpWebResponse = _
CType(ftp.GetResponse, System.Net.FtpWebResponse)
Using responseStream As IO.Stream = response.GetResponseStream
'loop to read & write to file
Using fs As New IO.FileStream(FTP_In_Path + File_Pattern, IO.FileMode.Create)
Dim buffer(2047) As Byte
Dim read As Integer = 0
Do
read = responseStream.Read(buffer, 0, buffer.Length)
fs.Write(buffer, 0, read)
Loop Until read = 0 '
responseStream.Close()
fs.Flush()
fs.Close()
End Using
responseStream.Close()
End Using
response.Close()
End Using
End Sub
Will really appreciate your help..
Thanks
shaky
bhishek