Question : Batch FTP Fetch File

I need to create a batch file to logonto an ftp server and download a file onto my pc depending on the filename into a specific folder

the filename is laid out as the following RH_POSTAL-mmdd-1.zip

i will need to modify this batch file to download a file named RH_POSTAL-mmdd-2.zip 3,4,5 and so on etc.

obviously the MMDD will change everyday so today is 01/08/08 so it would be 0801 tomorrow 0802 etc.

Thanks in advance

Superblades

Answer : Batch FTP Fetch File

Paste the script below into a text file with a .cmd extension.  Customize the indicated variable values with your local directory, remote directory of the files on the server, server name (or IP), username, and password.  Running the script will create an FTP script on the fly, execute it, then delete it.

Embedding the password in a script isn't the best practice from a security perspective, so you might want to change line 9 to something like this:
set /P pw=Enter your FTP password:

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
@echo off
setlocal
 
REM Customize these values
set localdir=c:\incoming\RH
set remotedir=\remotefiles
set server=yourftpserver.example.com
set user=yourusername
set pw=yourpassword
 
set mmdd=%date:~3,2%%date:~0,2%
 
if exist ftpscript.txt del ftpscript.txt
 
echo lcd "%localdir%" >> ftpscript.txt
echo open %server% >> ftpscript.txt
echo user %user% >> ftpscript.txt
echo %pw% >> ftpscript.txt
echo binary >> ftpscript.txt
echo prompt n >> ftpscript.txt
echo cd "%remotedir%" >> ftpscript.txt
echo mget RH_POSTAL-%mmdd%-*.zip >> ftpscript.txt
echo bye >> ftpscript.txt
 
ftp -n -s:ftpscript.txt
 
if exist ftpscript.txt del ftpscript.txt
Open in New Window Select All
Random Solutions  
 
programming4us programming4us