Question : automatically get file from ftp server using .bat and put onto my computer

I am running task scheduler to open up a .bat file that takes a csv file from my C: drive and loads it into a sql table in by database. I would like to automate the getting of the file from an FTP server as well.  Is there a way to automatically open up FileZilla, log in, find the file, and download the file to my C: drive in a bat file as well?

Any other suggestions would be greatly appreciated.

Thanks,
Robert

Answer : automatically get file from ftp server using .bat and put onto my computer

Hi Robert,
Yes.. it was a local address.. just replace that part with your server name. like below, and yes the path is the file with the commands (username, password, etc) substitue with your path... the log file is optional.

ftp -s:(script file) (Ftp server) (Optional ( > (log file)

Example:
ftp -s:C:\YourPath\ftpscript.txt datatransfer.cj.com  >  C:\YourPath\logfile.txt

About the folder date, I'm not sure what you are saying..
The remote (FTP) folder changes each day? or your local directory changes each day? If the local folder: Do you want to create a new folder to download into.. or your directory randomly changes each day and you want to put it into the newest folder?


As far as I know you can't use a variable folder name in the script file.. but the ftp program defaults to the directory it was started in. If what you wanted to do is download to a new folder each day you could do that in the batch file.. you wouldn't be able to change dir in the script however.. like this:
(note: the '%DATE:~4,2%%DATE:~7,2%%DATE:~10,4%' part could need modification because it depends on how your date is displayed, and change the "c:\temp" to your actual path)


Batch file:
--------------------------

cd c:\temp
md FTPDownload-%DATE:~4,2%%DATE:~7,2%%DATE:~10,4%
cd FTPDownload-%DATE:~4,2%%DATE:~7,2%%DATE:~10,4%
ftp -s:C:\YourPath\ftpscript.txt datatransfer.cj.com  >  C:\YourPath\logfile.txt

--------------------------


If you want to put it into the newest folder.. I'm not really great with batch files, but I think something like this should work, change the "c:\temp" to your actual path:


Batch file:
--------------------------
@echo off
set srcDir=C:\temp
set lastmod=
pushd "%srcDir%"
for /f "tokens=*" %%a in ('dir /ad /b /od 2^>NUL') do set lastmod=%%a
if "%lastmod%"=="" echo Could not locate folder.&goto :eof
cd %srcDir%\%lastmod%\
ftp -s:C:\YourPath\ftpscript.txt datatransfer.cj.com  >  C:\YourPath\logfile.txt  
--------------------------


Script file:
--------------------------


username
password
cd /path/on/ftpserver
bin
prompt
mget *
bye

--------------------------
Random Solutions  
 
programming4us programming4us