FTP date variable to grab ftp file












0















I am trying to write a script that will grab a file from an ftp site.



The issue I am having is figuring out how to grab the files that have dates on them. For example on January 1st we run mar2019. February 1st would run apr2019.



I am trying to figure out how to write something to automate this but cannot figure out how to grab the correct dated file.



Any help with this would be greatly appreciated.



u.ftp



open ftp.site.com 
username
password
mget 'Name.Name.RENEWALS.MAR2019'
disconnect
quit


run with



ftp -i -s:u.ftp









share|improve this question




















  • 3





    this (Get-Date).AddMonths(2).ToString('MMMyyyy') will give the short name for the current month plus 2, plus the year number. right now, i get Mar2019.

    – Lee_Dailey
    Jan 2 at 16:28








  • 1





    you haven't posted a script! [grin] i have no idea where you would put the code in a script i have never seen ...

    – Lee_Dailey
    Jan 2 at 16:30











  • u.ftp is a command input file for the ftp.exe program. it aint what one usually refers to as a script. [grin] there is NO place in that proprietary file for running powershell code. ///// you would need to write a PoSh script to modify that file by changing the mget line.

    – Lee_Dailey
    Jan 2 at 16:43


















0















I am trying to write a script that will grab a file from an ftp site.



The issue I am having is figuring out how to grab the files that have dates on them. For example on January 1st we run mar2019. February 1st would run apr2019.



I am trying to figure out how to write something to automate this but cannot figure out how to grab the correct dated file.



Any help with this would be greatly appreciated.



u.ftp



open ftp.site.com 
username
password
mget 'Name.Name.RENEWALS.MAR2019'
disconnect
quit


run with



ftp -i -s:u.ftp









share|improve this question




















  • 3





    this (Get-Date).AddMonths(2).ToString('MMMyyyy') will give the short name for the current month plus 2, plus the year number. right now, i get Mar2019.

    – Lee_Dailey
    Jan 2 at 16:28








  • 1





    you haven't posted a script! [grin] i have no idea where you would put the code in a script i have never seen ...

    – Lee_Dailey
    Jan 2 at 16:30











  • u.ftp is a command input file for the ftp.exe program. it aint what one usually refers to as a script. [grin] there is NO place in that proprietary file for running powershell code. ///// you would need to write a PoSh script to modify that file by changing the mget line.

    – Lee_Dailey
    Jan 2 at 16:43
















0












0








0








I am trying to write a script that will grab a file from an ftp site.



The issue I am having is figuring out how to grab the files that have dates on them. For example on January 1st we run mar2019. February 1st would run apr2019.



I am trying to figure out how to write something to automate this but cannot figure out how to grab the correct dated file.



Any help with this would be greatly appreciated.



u.ftp



open ftp.site.com 
username
password
mget 'Name.Name.RENEWALS.MAR2019'
disconnect
quit


run with



ftp -i -s:u.ftp









share|improve this question
















I am trying to write a script that will grab a file from an ftp site.



The issue I am having is figuring out how to grab the files that have dates on them. For example on January 1st we run mar2019. February 1st would run apr2019.



I am trying to figure out how to write something to automate this but cannot figure out how to grab the correct dated file.



Any help with this would be greatly appreciated.



u.ftp



open ftp.site.com 
username
password
mget 'Name.Name.RENEWALS.MAR2019'
disconnect
quit


run with



ftp -i -s:u.ftp






powershell cmd ftp






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 22:09









Squashman

9,20331933




9,20331933










asked Jan 2 at 15:59









David BriertonDavid Brierton

58021751




58021751








  • 3





    this (Get-Date).AddMonths(2).ToString('MMMyyyy') will give the short name for the current month plus 2, plus the year number. right now, i get Mar2019.

    – Lee_Dailey
    Jan 2 at 16:28








  • 1





    you haven't posted a script! [grin] i have no idea where you would put the code in a script i have never seen ...

    – Lee_Dailey
    Jan 2 at 16:30











  • u.ftp is a command input file for the ftp.exe program. it aint what one usually refers to as a script. [grin] there is NO place in that proprietary file for running powershell code. ///// you would need to write a PoSh script to modify that file by changing the mget line.

    – Lee_Dailey
    Jan 2 at 16:43
















  • 3





    this (Get-Date).AddMonths(2).ToString('MMMyyyy') will give the short name for the current month plus 2, plus the year number. right now, i get Mar2019.

    – Lee_Dailey
    Jan 2 at 16:28








  • 1





    you haven't posted a script! [grin] i have no idea where you would put the code in a script i have never seen ...

    – Lee_Dailey
    Jan 2 at 16:30











  • u.ftp is a command input file for the ftp.exe program. it aint what one usually refers to as a script. [grin] there is NO place in that proprietary file for running powershell code. ///// you would need to write a PoSh script to modify that file by changing the mget line.

    – Lee_Dailey
    Jan 2 at 16:43










3




3





this (Get-Date).AddMonths(2).ToString('MMMyyyy') will give the short name for the current month plus 2, plus the year number. right now, i get Mar2019.

– Lee_Dailey
Jan 2 at 16:28







this (Get-Date).AddMonths(2).ToString('MMMyyyy') will give the short name for the current month plus 2, plus the year number. right now, i get Mar2019.

– Lee_Dailey
Jan 2 at 16:28






1




1





you haven't posted a script! [grin] i have no idea where you would put the code in a script i have never seen ...

– Lee_Dailey
Jan 2 at 16:30





you haven't posted a script! [grin] i have no idea where you would put the code in a script i have never seen ...

– Lee_Dailey
Jan 2 at 16:30













u.ftp is a command input file for the ftp.exe program. it aint what one usually refers to as a script. [grin] there is NO place in that proprietary file for running powershell code. ///// you would need to write a PoSh script to modify that file by changing the mget line.

– Lee_Dailey
Jan 2 at 16:43







u.ftp is a command input file for the ftp.exe program. it aint what one usually refers to as a script. [grin] there is NO place in that proprietary file for running powershell code. ///// you would need to write a PoSh script to modify that file by changing the mget line.

– Lee_Dailey
Jan 2 at 16:43














1 Answer
1






active

oldest

votes


















2














The concept to insert a variable into a template and

write that to a file is the same in batch/powershell.



As getting/formatting the date is easier in PowerShell a here string is used for the template:



## Q:Test201912SO_54009396.ps1

$Month = (Get-Date).AddMonths(2).ToString('MMMyyyy')
$ftpScript = '.u.ftp'
@"
open ftp.site.com
username
password
mget 'Name.Name.RENEWALS.$Month'
disconnect
quit
"@ | Set-Content $ftpScript

&ftp -i -s:$ftpscript





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54009396%2fftp-date-variable-to-grab-ftp-file%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    The concept to insert a variable into a template and

    write that to a file is the same in batch/powershell.



    As getting/formatting the date is easier in PowerShell a here string is used for the template:



    ## Q:Test201912SO_54009396.ps1

    $Month = (Get-Date).AddMonths(2).ToString('MMMyyyy')
    $ftpScript = '.u.ftp'
    @"
    open ftp.site.com
    username
    password
    mget 'Name.Name.RENEWALS.$Month'
    disconnect
    quit
    "@ | Set-Content $ftpScript

    &ftp -i -s:$ftpscript





    share|improve this answer




























      2














      The concept to insert a variable into a template and

      write that to a file is the same in batch/powershell.



      As getting/formatting the date is easier in PowerShell a here string is used for the template:



      ## Q:Test201912SO_54009396.ps1

      $Month = (Get-Date).AddMonths(2).ToString('MMMyyyy')
      $ftpScript = '.u.ftp'
      @"
      open ftp.site.com
      username
      password
      mget 'Name.Name.RENEWALS.$Month'
      disconnect
      quit
      "@ | Set-Content $ftpScript

      &ftp -i -s:$ftpscript





      share|improve this answer


























        2












        2








        2







        The concept to insert a variable into a template and

        write that to a file is the same in batch/powershell.



        As getting/formatting the date is easier in PowerShell a here string is used for the template:



        ## Q:Test201912SO_54009396.ps1

        $Month = (Get-Date).AddMonths(2).ToString('MMMyyyy')
        $ftpScript = '.u.ftp'
        @"
        open ftp.site.com
        username
        password
        mget 'Name.Name.RENEWALS.$Month'
        disconnect
        quit
        "@ | Set-Content $ftpScript

        &ftp -i -s:$ftpscript





        share|improve this answer













        The concept to insert a variable into a template and

        write that to a file is the same in batch/powershell.



        As getting/formatting the date is easier in PowerShell a here string is used for the template:



        ## Q:Test201912SO_54009396.ps1

        $Month = (Get-Date).AddMonths(2).ToString('MMMyyyy')
        $ftpScript = '.u.ftp'
        @"
        open ftp.site.com
        username
        password
        mget 'Name.Name.RENEWALS.$Month'
        disconnect
        quit
        "@ | Set-Content $ftpScript

        &ftp -i -s:$ftpscript






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 2 at 17:20









        LotPingsLotPings

        20k61633




        20k61633
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54009396%2fftp-date-variable-to-grab-ftp-file%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            Npm cannot find a required file even through it is in the searched directory