Solved GET file from FTP Site

February 2, 2016 at 06:21:41
Specs: Windows 7
I have requirement to fetch a file from the FTP Site. The file name is fcmmdd.txt where mm is the month and dd is the day of the month. I used this script and got Syntax Incorrect Error

open ftpsite
user
pwd
lcd \\FetchFiles
ascii
get fc%Date:~4,2%%Date:~7,2%.txt
disconnect
quit


See More: GET file from FTP Site

Report •


✔ Best Answer
February 2, 2016 at 19:34:42
Usually, if using the standard FTP client for windows, I just have batchscript write the FTP commands out to a FTP script, then run FTP -s scriptfilename.
:: build the FTP-script-file using batch, but which is NOT BATCH script!
set mmdd=fc%date:~4,2%%date:~7,2%.txt
>>ftpscript (
echo open ftpsite
echo user whatever
echo pwd whatever-else
echo lcd \\FetchFiles
echo ascii
echo get %mmdd%
echo more commands until done with session
echo disconnect
echo quit
)
ftp -n -s ftpscript

Also, I will assume that your date %date% format includes DOFW as the first four char.s, like: WED 01/23/2016 since otherwise it made no sense.

message edited by nbrane



#1
February 2, 2016 at 06:28:45
Is it working?

Or what?

=====================

M2 Get custom script or take private lessons


Report •

#2
February 2, 2016 at 07:25:49
I get a syntax error when I use this command

get fc%Date:~4,2%%Date:~7,2%.txt

what is the correct syntax to get the file which has a dynamic name like this?

message edited by rlan123


Report •

#3
February 2, 2016 at 08:44:57
I guess your script is driving the FTP command. If so you can't blend batch commands and ftp orders. If you confirm what I am supposing, I can post the solution for your issue.

message edited by IVO


Report •

Related Solutions

#4
February 2, 2016 at 09:02:28
Please, post also the exacy fornat of your date variable since it is country dependent (e.g. in Italy we use dd/mm/yyyy).

Report •

#5
February 2, 2016 at 14:29:46
Yes, The script is driving the ftp command. The date format is mm/dd/yyyy.

Report •

#6
February 2, 2016 at 19:34:42
✔ Best Answer
Usually, if using the standard FTP client for windows, I just have batchscript write the FTP commands out to a FTP script, then run FTP -s scriptfilename.
:: build the FTP-script-file using batch, but which is NOT BATCH script!
set mmdd=fc%date:~4,2%%date:~7,2%.txt
>>ftpscript (
echo open ftpsite
echo user whatever
echo pwd whatever-else
echo lcd \\FetchFiles
echo ascii
echo get %mmdd%
echo more commands until done with session
echo disconnect
echo quit
)
ftp -n -s ftpscript

Also, I will assume that your date %date% format includes DOFW as the first four char.s, like: WED 01/23/2016 since otherwise it made no sense.

message edited by nbrane


Report •

#7
February 3, 2016 at 02:15:01
Well, nbrane solved your issue, anyway I post my solution, just a variant of what above

:: ftpcmd.bat Usage: ftpcmd
@echo off
(
echo.open ftpsite
echo.user
echo.pwd
echo.lcd \\FetchFiles
echo.ascii
echo.get fc%Date:~4,2%%Date:~7,2%.txt
echo.disconnect
echo.quit
) | ftp

message edited by IVO


Report •

#8
February 3, 2016 at 06:35:11
Thank you nbrane and IVO for the suggestions. Created a batch script to write the FTP commands to a FTP script and it works.

Report •

#9
February 7, 2016 at 05:18:43
Hi IVO

As usual yours is much better than mine.

=====================

M2 Get custom script or take private lessons


Report •


Ask Question