Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6577741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:40:37+00:00 2026-05-25T15:40:37+00:00

I am writing a script using ftp.exe to download files from an FTP server,

  • 0

I am writing a script using ftp.exe to download files from an FTP server, it works at first. But the version I wrote was suited for only one file and the current date. My script is below:

echo user>>ftp.txt
echo password>>ftp.txt
set prefix=%date:~0,10%
set "name=%prefix%.txt"
echo get %name% >> ftp.txt
echo bye >> ftp.txt
ftp -s:ftp.txt ftpserver.com
del ftp.txt

But now there are more than one file named like aa-bb-2011-09-13.0.log,
aa-bb-2011-09-13.1.log,
aa-bb-2011-09-13.10.log. The last number is a serial number, it could be 0, 1, 2, 3…

How could download these files by batch script? How to modify my script to download more than one file (the number is unknown) which file name pattern is yesterday?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:40:38+00:00Added an answer on May 25, 2026 at 3:40 pm

    In terms of downloading multiple files, use mget instead of get. The former allows you to specify wildcards for getting rather than specific files.

    You’ll just have to construct the “name” with a wildcard pattern, and make sure you have a prompt in your script before mget otherwise it will ask for confirmation on every file.

    This is untested, but it’s probably as simple as changing:

    echo get %name% >> ftp.txt
    

    to something like:

    echo prompt>>ftp.txt
    echo mget *%prefix%*>>ftp.txt
    

    In terms of getting yesterdays date, you can use the following script. It’s pretty complex compared to what you would do in, for example bash, but it works.

    @setlocal enableextensions enabledelayedexpansion
    @echo off
    
    rem Get the date from WMI (on one line).
    
    for /f "skip=2 tokens=2-7 delims=," %%A in ('wmic 
            path win32_localtime get day^,month^,year^ /format:csv') do (
        set /a "yest_yyyy = %%C"
        set /a "yest_mm = %%B"
        set /a "yest_dd = %%A"
    )
    
    rem Not the first of the month, just decrement day.
    
    if not %yest_dd%==1 (
        set /a yest_dd = yest_dd - 1
        goto done
    )
    
    rem Jan 1, set to Dec 31 previous year.
    
    if %yest_mm%==1 (
        set /a "yest_dd = 31"
        set /a "yest_mm = 12"
        set /a "yest_yyyy = yest_yyyy - 1"
        goto :done
    )
    
    rem Any other day, decrement month.
    
    set /a "yest_mm = yest_mm - 1"
    
    rem Need to find last day, default to 31.
    
    set dim=31
    
    rem Apr/Jun/Sep/Nov all have 30 days. Feb gets special handling.
    
    if %yest_mm%==4 set dim=30
    if %yest_mm%==6 set dim=30
    if %yest_mm%==9 set dim=30
    if %yest_mm%==11 set dim=30
    if not %yest_mm%==2 goto :got_dim
    
    rem Default Feb to 28 then use rules to override.
    
    set dim=28
    
    set /a "divid=yest_yyyy%%400"
    if "%divid%"=="0" goto daysinmonth_29days
    set /a "divid=yest_yyyy%%100"
    if "%divid%"=="0" goto :done
    set /a "divid=yest_yyyy%%4"
    if not "%divid%"=="0" goto :done
    
    rem Adjust to 29 days.
    
    :daysinmonth_29days
    
    set dim=29
    
    :done
    
    rem Pad out and return value.
    
    if %yest_mm% lss 10 set yest_mm=0%yest_mm%
    if %yest_dd% lss 10 set yest_dd=0%yest_dd%
    
    set yesterday=%yest_yyyy%-%yest_mm%-%yest_dd%
    
    endlocal && set yesterday=%yesterday%
    

    It will set the yesterday environment variable to the format YYYY-MM-DD so that you can use it in your current script. Simply invoke call yesterday.cmd and then use the environment variable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a script to download files from an FTP server using cURL +
I'm writing a script that can FTP files and folders using PHP functionality. I'm
I am writing a script to download files from a password protected members area.
I am writing a shell script and need to download patches using ftp. There
I am writing python script to login to ssh server using paramiko. I wrote
Need help writing a script downloads data from google insight using c# this is
I'm writing a PHP script that downloads a series of generated files (using wget
I'm currently writing a small script using pygame, but I don't believe this question
Using perl 5.8.8 on windows server I am writing a perl cgi script using
I'm using SQL Server MS. I'm having trouble writing this script: CREATE VIEW rental_view

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.