Script to extract files information from ftp server

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aiko27
    New Member
    • Sep 2008
    • 5

    Script to extract files information from ftp server

    Hi

    Wonder if you could help me with the following please.

    I would like to construct a script (in any language whichever it's easiest) which when run, it will log on to a ftp server using a generic account and password, then list the files in a specific folder that begins with the string "abc". The file names along with their creation date are then to be extracted on a csv file (or similar). Can this be easily done?

    Many thanks in advance!!

    Ken
  • Flugeldorph
    New Member
    • Oct 2008
    • 11

    #2
    Hello,

    There is a scripting language available free from NIST (http://expect.nist.gov/) called Expect which is quite easy to learn, that would work well for what you are trying to do, if, on the other hand you already know the file that you want to download, the following would work in VB

    Code:
       Private Sub GetFCCDataFile()
          Dim CurrentDirectory As String = Application.StartupPath() + "\"
          Dim DestinationDirectory As String = CurrentDirectory + "DataFiles\"
          Dim FileName As String = "l_amat.zip"
          Dim remoteUri As String = "http://wireless.fcc.gov/uls/data/complete/"
          Dim Downloadfile As String = remoteUri + FileName
          Dim myWebClient As New System.Net.WebClient()
    
          Try
             ' Determine whether the directory already exists.
             If System.IO.Directory.Exists(DestinationDirectory) = True Then
                ' Delete the target to ensure it is not there.
                System.IO.Directory.Delete(DestinationDirectory, True)
             End If
             ' Create the directory.
             System.IO.Directory.CreateDirectory(DestinationDirectory)
             ' Move to data directory
             System.IO.Directory.SetCurrentDirectory(DestinationDirectory)
             ' Download the file
             myWebClient.DownloadFile(Downloadfile, FileName)
             ' Restore original directory
             System.IO.Directory.SetCurrentDirectory(CurrentDirectory)
          Catch ex As Exception
             Console.WriteLine("Unable to download file: {0}", ex.ToString())
          End Try
       End Sub
    Larry

    Comment

    Working...