Computing Staff
  • 42

How To Copy Yesterday File From Ftp Via A Batch File?

  • 42

I wrote a script to copy a file from ftp

@echo off
ftp -s:ftp.txt
pausa

and the ftp.txt Contains :

open= ftp server
username
password
get ://ftpserver/ghwt/jdtt_05gbser.txt
quit

now i wont to Improve it to copy only yesterday file, What and Where I should add in my script?

Share

2 Answers

  1. @Echo Off
    Set _FTPServerName= ftp site address
    Set _UserName= username
    Set _Password= password
    Set _LocalFolder= C:\FTPFiles
    Set _RemoteFolder= Public\Reports\CSV
    Set _Filename= report.csv
    Set _ScriptFile=ftp1
    :: Create script
    >”%_ScriptFile%” Echo open %_FTPServerName%
    >>”%_ScriptFile%” Echo %_UserName%
    >>”%_ScriptFile%” Echo %_Password%
    >>”%_ScriptFile%” Echo lcd %_LocalFolder%
    >>”%_ScriptFile%” Echo cd %_RemoteFolder%
    >>”%_ScriptFile%” Echo binary
    >>”%_ScriptFile%” Echo get %_Filename%
    >>”%_ScriptFile%” Echo quit
    :: Run script
    ftp -s:”%_ScriptFile%”
    Del “%_ScriptFile%”

    Does this help?

    • 0
  2. If you can’t generate the ftp-filename from your end, you have a long row to hoe: download a “dir” of the ftp directory, convert dates, subtract converted dates from today’s date, download all files that qualify. If it came to that, I would strive, mightily, to find a better way. “jdtt_05gbser.txt” tells me zilch about any relationship to previous filenames or the file’s date.

    • 0