DOS script tp FTP from a remote server and copy files to local folder

copydosftp

I need to write a single dos script which will first FTP from a remote server to my local directory and then will copy these files to another folder within the local machine. The reason behind the second step is that the destination folder path is based on whether the SYSTEM Processor of 32-bit or 64-bit.

I have two separate scripts which are working fine now. But when I am putting them together in a single script, it is failing with the ftp command prompt. Here is the script which I am using –

@echo off
:MAIN

SETLOCAL ENABLEDELAYEDEXPANSION


set winver=%PROCESSOR_ARCHITECTURE%

rmdir c:\batch\temp

mkdir c:\batch\temp

goto :ftpbegin

:ftpbegin

@ftp -i -s:"%~f0"&GOTO:EOF
open x.y.z.a
<userid>
<password>
!:-----FTP commands here -----
lcd C:\batch\temp
cd CGServices\Uploads
binary
mget "*.psl"
mget "*.PST"
mget "*.psy"
get abc.ini
get def.pmd
disconnect
bye

:eof

exit /b


:findwin

if %winver% ==x86 (goto :copywin32) else (goto :copywin64)


:copywin32

echo "inside copywin32"

<do the copy files here>

:copywin64
<do copy files here>

exit /b 0

However, the ftp script seems to cause a break while executing the second part of my program since it is calling the program in a loop in ftp prompt. So, none of the dos commands are translated on FTP prompt.

Any help on how to achieve this in a single script for this is highly appreciated.

thanks,
Sanders

Best Answer

The FTP command AFAIK cannot process the commands from the command line without reading the ftp commands from an external file. I usually download a windows version of wget, and it works well for us, perhaps you would like to have a look at that.

Here is the manual for wget http://www.editcorp.com/Personal/Lars_Appel/wget/v1/wget_7.html

for example

wget ftp://<user>:<password>@server.com/upload/file.ext
Related Topic