Issue
I am working on a download feature for my GUI that will allow the end user to be able to input a 5 digit job number and download only those files from the FTP site. In doing this, I have been able to get a list of the directory, but I have not been able to use that list to get the files. Any help on the code shown would be appreciated.
Dim UserName As String
' Sets Username to current logged-in user profile
UserName = Environment.UserName
Dim JobNo As String
JobNo = Textbox1.Text
Dim listRequest As FtpWebRequest = WebRequest.Create("ftp://ftp.site.com/INPUT/" & JobNo & "_*.DBF")
listRequest.Credentials = New System.Net.NetworkCredential(“Username”, “Password”)
listRequest.Method = WebRequestMethods.Ftp.ListDirectory
Dim listResponse As FtpWebResponse = listRequest.GetResponse()
Dim reader As StreamReader = New StreamReader(listResponse.GetResponseStream())
For Each foundFile As String In
My.Computer.Network.DownloadFile("ftp://ftp.site.com/INPUT/" & foundFile, "C:\users\” & UserName & “\desktop\temp\" & foundFile, “Username”, “Password”)
Next
Solution
Below is the final output that worked. The overall
Dim UserName As String
' Sets Username to current logged-in user profile
UserName = Environment.UserName
Dim JobNo As String
JobNo = Textbox1.Text
'DOWNLOADING FROM THE FTP JOBS PROCESSED FOLDER
Dim listRequest As FtpWebRequest = WebRequest.Create(“ftp.site.com/input/” & JobNo & "_*.DBF")
listRequest.Credentials = New System.Net.NetworkCredential(“Username”, “Password”)
listRequest.Method = WebRequestMethods.Ftp.ListDirectory
Dim listResponse As FtpWebResponse = listRequest.GetResponse()
Dim reader As StreamReader = New System.IO.StreamReader(listResponse.GetResponseStream())
Dim Filedata As String = reader.ReadToEnd
Dim directory() As String = Filedata.Split(New String() {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
'CREATES TEAM FILE FOLDERS ON LOCAL COMPUTER
My.Computer.FileSystem.CreateDirectory("C:\users\" & UserName & "\desktop\TEAMFILES\IMB_APPEND\A_TEAM")
My.Computer.FileSystem.CreateDirectory("C:\users\" & UserName & "\desktop\TEAMFILES\IMB_APPEND\B_TEAM")
'CLEAR TEXTBOX2
TextBox2.Clear()
For Each foundFile As String In directory
ATEAMdown(foundFile)
TextBox2.Text = TextBox2.Text & foundFile & vbNewLine
Next
'DOWNLOADING FROM THE IMB FTP XMPIE TEAM FOLDER
listRequest = WebRequest.Create(“ftp.site.com/input/” & JobNo & "_*.DBF")
listRequest.Credentials = New System.Net.NetworkCredential(“Username”, “Password”)
listRequest.Method = WebRequestMethods.Ftp.ListDirectory
listResponse = listRequest.GetResponse()
reader = New System.IO.StreamReader(listResponse.GetResponseStream())
Filedata = reader.ReadToEnd
directory = Filedata.Split(New String() {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
For Each foundFile As String In directory
BTEAMdown(foundFile)
TextBox2.Text = TextBox2.Text & foundFile & vbNewLine
Next
Answered By - John D Answer Checked By - Willingham (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.