PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, August 1, 2022

[FIXED] How to search an FTP ListDirectory for a pattern to download specific files

 August 01, 2022     ftp, vb.net     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing