I have been assigned a task to automate an ftp download each morning. The file name stays the same except for a date suffix that is appended on the end of it.
I have the username and password and ftp site, but nothing I've found seems to allow me to connect. I've written one batch files to synchronize network drives and my hard drive for the purpose of backing up my material. So needless to say, I'm very new to batch scripting. Someone told me I needed the IP address, but I've seen multiple examples of batch files that don't use the IP. I would appreciate any direction.
open ftp.site.com
user {username}
{password]
prompt
mget File_20100702.csv
bye
Also the file changes every day, FileName_{Today, Format("yyyymmdd")}
If anyone could explain how I might put that as a variable or something so I don't have to edit the batch file every day, that would be great as well.
New to batch files, need to automate ftp download.
Moderator: DosItHelp
Re: New to batch files, need to automate ftp download.
I'm not that familar with FTP, but this is doable.
First have a look at these examples.
To assemble the date to the right format I need to know what an
echo %date%
would display on your computer.
Regards
aGerman
First have a look at these examples.
To assemble the date to the right format I need to know what an
echo %date%
would display on your computer.
Regards
aGerman
Re: New to batch files, need to automate ftp download.
ECHO %date% gives me DayOfWeek(Three letters) mm/dd/yyyy.
Thanks.
Also I had checked out that link and is where I came up with the model I am working with.
I realize I'm going to get more files than I want at the moment, but I wanted to see if it would work.
It didn't.
Thanks.
Also I had checked out that link and is where I came up with the model I am working with.
Code: Select all
open example.com
username
password
!:--- FTP commands below here ---
lcd I:\ImportantFiles\Brandon
mget "{Filename}*"
disconnect
bye
I realize I'm going to get more files than I want at the moment, but I wanted to see if it would work.
It didn't.
Re: New to batch files, need to automate ftp download.
A FTP file is no batch file. You could write and call it by batch.
Try something like that:
Regards
aGerman
Try something like that:
Code: Select all
@echo off &setlocal
for /f "tokens=2-4 delims=/ " %%a in ("%date%") do set "dateStamp=%%c%%a%%b"
set "ftpFile=%temp%\get.ftp"
>"%ftpFile%" echo.open example.com
>>"%ftpFile%" echo.username
>>"%ftpFile%" echo.password
>>"%ftpFile%" echo.lcd I:\ImportantFiles\Brandon
>>"%ftpFile%" echo.mget File_%dateStamp%.csv
>>"%ftpFile%" echo.disconnect
>>"%ftpFile%" echo.bye
ftp -v -i -s:"%ftpFile%"
del "%ftpFile%"
pause
Regards
aGerman
Re: New to batch files, need to automate ftp download.
It says unknown host..
I use the same path in IE and it works, but if I try it through this it doesn't recognize it. Any suggestions?
I use the same path in IE and it works, but if I try it through this it doesn't recognize it. Any suggestions?
Re: New to batch files, need to automate ftp download.
Is your file placed directly on the host or on a share?
Say your file is placed on //ftp:ftp.site.com/share/ you have to use the "cd" command. "open" is only for the host.
Regards
aGerman
Say your file is placed on //ftp:ftp.site.com/share/ you have to use the "cd" command. "open" is only for the host.
Code: Select all
@echo off &setlocal
for /f "tokens=2-4 delims=/ " %%a in ("%date%") do set "dateStamp=%%c%%a%%b"
set "ftpFile=%temp%\get.ftp"
>"%ftpFile%" echo.open ftp.site.com
>>"%ftpFile%" echo.username
>>"%ftpFile%" echo.password
>>"%ftpFile%" echo.lcd I:\ImportantFiles\Brandon
>>"%ftpFile%" echo.cd share
>>"%ftpFile%" echo.mget File_%dateStamp%.csv
>>"%ftpFile%" echo.disconnect
>>"%ftpFile%" echo.bye
ftp -v -i -s:"%ftpFile%"
del "%ftpFile%"
pause
Regards
aGerman
Re: New to batch files, need to automate ftp download.
So if I type in ftp:username:password@ftp.site.com in my browser, it takes me directly to the place I need to download the file.
Are you saying that instead of using the open ftp.site.com command, I need to do something like this?
@echo off &setlocal
for /f "tokens=2-4 delims=/ " %%a in ("%date%") do set "dateStamp=%%c%%a%%b"
set "ftpFile=%temp%\get.ftp"
>"%ftpFile%" echo.cd ftp.site.com
>>"%ftpFile%" echo.username
>>"%ftpFile%" echo.password
>>"%ftpFile%" echo.lcd I:\ImportantFiles\Brandon
>>"%ftpFile%" echo.mget File_%dateStamp%.csv
>>"%ftpFile%" echo.disconnect
>>"%ftpFile%" echo.bye
ftp -v -i -s:"%ftpFile%"
del "%ftpFile%"
pause
That just tells me that the host has not connected. Sorry for the troubles. I am confused.
Are you saying that instead of using the open ftp.site.com command, I need to do something like this?
@echo off &setlocal
for /f "tokens=2-4 delims=/ " %%a in ("%date%") do set "dateStamp=%%c%%a%%b"
set "ftpFile=%temp%\get.ftp"
>"%ftpFile%" echo.cd ftp.site.com
>>"%ftpFile%" echo.username
>>"%ftpFile%" echo.password
>>"%ftpFile%" echo.lcd I:\ImportantFiles\Brandon
>>"%ftpFile%" echo.mget File_%dateStamp%.csv
>>"%ftpFile%" echo.disconnect
>>"%ftpFile%" echo.bye
ftp -v -i -s:"%ftpFile%"
del "%ftpFile%"
pause
That just tells me that the host has not connected. Sorry for the troubles. I am confused.
Re: New to batch files, need to automate ftp download.
No. You need the "open" command. But if the file is placed in a sub folder you must not write the entire path behind the "open" command. Once more, I wrote:
...
...
So the question was if the file is placed directly on "ftp.site.com" or is it placed in a subfolder.
Hope you will understand, what I try to explain.
Regards
aGerman
Say your file is placed on //ftp:ftp.site.com/share/...
...
>"%ftpFile%" echo.open ftp.site.com
...
>>"%ftpFile%" echo.cd share
So the question was if the file is placed directly on "ftp.site.com" or is it placed in a subfolder.
Hope you will understand, what I try to explain.
Regards
aGerman