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 7640415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:39:56+00:00 2026-05-31T08:39:56+00:00

Found several solutions for local, but need one for FTP action: I have a

  • 0

Found several solutions for local, but need one for FTP action:

I have a daily batch script to backup MySQL databases locally, however I also ftp them to a backup server.

Locally, I am using forfiles to delete files older than 14 days:

forfiles -p "C:\whatever" -s -m *.* -d 14 -c "cmd /c del @path"`

The same I would like to do on FTP, once the newest backup files are dumped into FTP server running on Windows Server 2008 R2.

How do I extend my batch file to do this action?

cd\[path to directory where files are saved] 
echo off
echo user [ftp username]>ftpup.dat
echo [ftp password]>>ftpup.dat
echo binary>>ftpup.dat
echo put [FullBackup.%backupdate%.zip]>>ftpup.dat
echo quit>>ftpup.dat
ftp -n -s:ftpup.dat [myserver.com]
del ftpup.dat
  • 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-31T08:39:57+00:00Added an answer on May 31, 2026 at 8:39 am
    1. capture the list of files you are interested in

      echo user [ftp username]>ftpdir.txt
      echo [ftp password]>>ftpdir.txt
      echo dir . ftplist.txt >>ftpdir.txt
      echo quit>>ftpdir.txt
      ftp -n -s:ftpdir.txt [myserver.com]
      
    2. prepare the ftp delete script

      echo user [ftp username]>ftpdel.txt
      echo [ftp password]>>ftpdel.txt
      
    3. process the list

       for /f "tokens=6,7,8,*" %%a in (ftplist.txt) do (
          echo %%d
       )
      
    4. inside the loop, extract the file date.

      echo %%c %%a %%b - %%d
      

      And transform the month name into a number

      call :month %%a
      

      you may use the routine found in http://www.dostips.com/DtTipsStringManipulation.php

    5. inside the loop, transform the date into a number of days since today

      call :days %%c %month% %%b
      

      this is a call to a routine that computes the days using the Fliegel-Van Flandern algorithm. See this SO question for details and implementation How can I check the time stamp creation of a file in a Windows batch script?

    6. and finally, inside the loop, compare the resulting number, if it is bigger than, say, 14, add the file to the files to delete ftp script

      IF !days! GEQ 14 echo DEL %%d >>ftpdel.txt
      
    7. finish the ftp del script and execute it

      echo quit>>ftpdel.txt
      ftp -n -s:ftpdel.txt [myserver.com]
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have found several topics with this title, but none of their solutions worked
I've tried several of the solutions that I've found here, but none seem to
I have tried several solutions I found on github (like rolling back to rake
I've found several solutions online, but none that really do what I'm looking for.
I found partial solutions on several sites, so I pulled several parts together, but
test image here: http://images.plurk.com/tn_4134189_bf54fe8e270ce41240d534b5133884ee.gif I've tried several solutions found on the internet but there
I found several controlsets for that nice looking ribbons (DotNetBar, DivElements, ...), but all
I have found several other questions here on S.O. (and the web in general)
In my Gradle script (version 0.8), I have a local ivy repository which I
I've found this question asked several times when I've Googled for it, but the

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.