Downloading files from an external FTP server.

Tagged: 

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Andrew Andrew 4 months ago.

  • Author
    Posts
  • #62211
    Profile photo of Andrew
    Andrew
    Participant

    I need to write a script to download spefic file(s) daily from an ftp server to a local directory. The names of these file will change daily (but adhere to a basic naming convention), so the script will need to be flexible enough to look for subsections of the file name string in order to make the determination of which files to download (more than likely with wild card's).

    I've been able to find a number of examples on various support forums, but most are for only one file and are hardcoded for a specific name.

    Can anyone advise or point me in the direction of an article/link that might help with this?

  • #62236
    Profile photo of Ron
    Ron
    Participant

    Can you give examples of the file name(s) you want to download, and how they change from day to day?

  • #62253
    Profile photo of Andrew
    Andrew
    Participant

    The naming convention of the files I need to pull from the ftp server is as follows

    L6XQ(Month)(Day)

    So in this Format

    L6XQ0117

    I no longer need to change the names after they arrive in the local directory.

    So far I have the following.

    $MyCredential = Import-Clixml -Path "C:\Cred\PW1"
    $LocalDirectory = "C:\PF_FTP\Received\"
    $PFFTP = "ftp//10.15.20.25/OutFiles\L6XQ*.*.txt"
    $WebClient = New-Object System.Net.WebClient
    $URI = New-Object System.Uri ($PFFTP)
    $WebClient.DownloadFile ($URI, $LocalDirectoryTemp)

    Can you advise if L6XQ*.*.txt would identify the files I need.

You must be logged in to reply to this topic.