1.

Solve : Batch with copy from Internet?

Answer»

ey I like to make a batch with a code that copy's file(s) from a ftp or http server on the INTERNET
can i do that ?Using HTML may be tricky. With FTP it is doable.

The example shown below will download all *.xml files from the FTP server's sub directory public_html into the directory where the batch file is LOCATED. The batch file extracts the FTP script embedded at the end of the file and executed it in FTP.EXE context.

This and more sophisticated examples that let you configure the connection and directory settings at run-time are available at [highlight]http://dostips.cmdtips.com/DtCodeBatchFiles.php[/highlight].


Code: [Select]@ECHO OFF
REM.-- Prepare the Command Processor
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION


rem --build the FTP script as <ThisFileName>.txt
set FtpScript=%~dpn0+.ftp
type nul>"%FtpScript%"
call:extractFromFile ##FtpScript##>>"%FtpScript%"


rem --Execute the FTP script
ftp -i -s:"%FtpScript%"
set title=Done


REM.-- End of application
FOR /l %%a in (5,-1,1) do (TITLE %title% -- closing in %%as&ping -n 2 -w 1 127.0.0.1>NUL)
TITLE PRESS any key to close the application&ECHO.&GOTO:EOF


::------------------------------------------------------------------
::-- functions start below here
::------------------------------------------------------------------


:extractFromFile - extract lines from a file between begin and end mark
:: - %~1: begin mark, use '...$' mark to allow variable substitution
:: - %~2: optional end mark, default is end of file
:: - %~3: optional source file, default is THIS file
SETLOCAL
set bmk=%~1
set emk=%~2
set src=%~3
set /a b=-1
set /a e=-1
if "%src%"=="" set src=%~f0& ::- if no source file then assume THIS file
for /f "tokens=1,* delims=:" %%a in ('"findstr /n /b /c:"%bmk%" "%~f0""') do (
set b=%%a
set bmk=%%b
)
if /i %b%==-1 echo.ERROR: begin mark '%bmk%' not found in '%src%'&GOTO:EOF
if "%emk%"=="" (set /a e=2000000000) ELSE (
for /f "delims=:" %%a in ('"findstr /n /b /c:"%emk%" "%~f0""') do (
if /i %b% LSS %%a if /i !e!==-1 set e=%%a& rem -- find only the first one after b
)
)
if /i %e%==-1 echo.ERROR: end mark '%emk%' missing in '%src%'&GOTO:EOF
if /i %b% GEQ %e% echo.ERROR: end mark '%emk%' detected before begin mark '%bmk%' in '%src%'&GOTO:EOF
for /f "delims=: tokens=1,*" %%a in ('"findstr /v /n /b /c:"#$*ReturnAll*$#" "%src%""') do (
if /i %b% LSS %%a if /i %%a LSS %e% (
if "%bmk:~-1%"=="$" (
rem --substitution variables within %%b
call echo.%%b
) ELSE (
rem --no variable substitution
echo.%%b
)
)
)
GOTO:EOF


::------------------------------------------------------------------
::-- ftp script starts below here
::------------------------------------------------------------------


##FtpScript##$
open example.com
anonymous
[emailprotected]
^!: THIS IS A COMMENT
^!: Put your FTP script below here, e.g.:
^!: change the local directory to be the location of the batch file
lcd %~dp0.
^!: set the target directory
cd public_html
^!: upload all xml files
mget *.xml
^!: end of FTP session
bye

Hope this helps and how do i copy that downloaded file ( it really works thank you ) to lets say C:\Program Files\MSN Messenger\

were do i have to write it ?


thank you
MisterMerlijnspecify the target directory using ftp's lcd command like this:

open example.com
anonymous
[emailprotected]
lcd "C:\Program Files\MSN Messenger\"
cd public_html
mget *.xml
bye


Was this your questions?no.. i think not

lets ..
when i give you a batch with the code for ftp.. and that ftp downloads a .gif
that downloaded file needs to go to c:\Program Files\MSN Messenger


is that possible ?
When you exit from FTP session, you can do from ms-dos:
move that.gif "C:\Program Files\MSN Messenger\"

The previous post must WORK fine, with lcd (Local Call Directory) all your downloads must be saved in the directory you choose (e.g. "C:\Program Files\MSN Messenger\")

If don't work for you :-?, try to download all the files in a temp directory and then, copy all files in "C:\Program Files\MSN Messenger\":

Code: [Select]ftp> !md tmp
ftp> lcd tmp
ftp> get that.gif
ftp> !move that.gif "C:\Program Files\MSN Messenger\"
...
ftp> lcd ..
ftp>!rd /s tmp

P.S. If you have interest, you can use the program wget:

Quote

"GNU Wget is a free software package for retrieving files using HTTP, HTTPS and FTP, the most widely-used Internet protocols. It is a non-interactive commandline tool, so it may easily be called from scripts, cron jobs, terminals without Xsupport, etc"
[/i]

This is the official page:

http://www.gnu.org/software/wget/wget.html

You can download a version Windows for wget here:

http://users.ugent.be/~bpuype/wget/


Discussion

No Comment Found