Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help: Simple batchfile with FTP-commands

0 views
Skip to first unread message

Jörgen Gustafsson

unread,
Sep 20, 1999, 3:00:00 AM9/20/99
to
Hello,
I'm trying to write a simple batch-file in NT/Dos that
will include some FTP-commands to download a file
but only the first line in the .cmd file will execute..??!!
(After I get this to work I would like to schedule this
with the "AT" command...)

It seems like I have to type the "enter" commands in some way....

The code looks something like this (ftpget.cmd)

ftp
open someipadress
theusername
thepassword
get 'aaa.bbb.ccc' c:\myfile.txt
quit

Thanx in advance..!!

//Jörgen

jor...@weblabbet.se

Damian Yerrick

unread,
Sep 20, 1999, 3:00:00 AM9/20/99
to

Jörgen Gustafsson <jor...@weblabbet.se> wrote in message
news:37e6591a.33747225@news...

> Hello,
> I'm trying to write a simple batch-file in NT/Dos that
> will include some FTP-commands to download a file
> but only the first line in the .cmd file will execute..??!!
> (After I get this to work I would like to schedule this
> with the "AT" command...)
>
> It seems like I have to type the "enter" commands in some way....
>
> The code looks something like this (ftpget.cmd)
>
> ftp

Try this one-line ftpget.bat:

ftp < ftpget.cmd

If ftp.exe normally reads commands from stdin, it'll read commands from
ftpget.cmd instead. Put these lines into ftpget.cmd

open 123.456.789.123
jorgen
thepassword
get 'foo.bar' c:\myfile.txt
quit

Damian Yerrick
http://pineight.webjump.com

Speaker to Animals

unread,
Sep 20, 1999, 3:00:00 AM9/20/99
to
On Mon, 20 Sep 1999 16:03:38 GMT, jor...@weblabbet.se (Jörgen
Gustafsson) wrote:

I know "ftp -s:inputfilename" works in 9X, probably NT too.

>Hello,
>I'm trying to write a simple batch-file in NT/Dos that
>will include some FTP-commands to download a file
>but only the first line in the .cmd file will execute..??!!
>(After I get this to work I would like to schedule this
>with the "AT" command...)
>
>It seems like I have to type the "enter" commands in some way....
>
>The code looks something like this (ftpget.cmd)
>
>ftp

>open someipadress
>theusername
>thepassword
>get 'aaa.bbb.ccc' c:\myfile.txt
>quit
>
>Thanx in advance..!!
>
>//Jörgen
>
>jor...@weblabbet.se
>

Speaker to Animals
spe...@kzin.com
http://www.kzin.com

Phil Robyn

unread,
Sep 20, 1999, 3:00:00 AM9/20/99
to
"Jörgen Gustafsson" wrote:

> Hello,
> I'm trying to write a simple batch-file in NT/Dos that
> will include some FTP-commands to download a file
> but only the first line in the .cmd file will execute..??!!
> (After I get this to work I would like to schedule this
> with the "AT" command...)
>
> It seems like I have to type the "enter" commands in some way....
>
> The code looks something like this (ftpget.cmd)
>
> ftp
> open someipadress
> theusername
> thepassword
> get 'aaa.bbb.ccc' c:\myfile.txt
> quit
>
> Thanx in advance..!!
>
> //Jörgen
>
> jor...@weblabbet.se

The following is adapted from a .CMD file that I use all the time on NT;
I think that
I have made it generic enough that it will work on Win 9x as well (but I
cannot test
it on non-NT platform). For clarity, all the lines have line numbers;
do not include
these in your batch file. Any line that does not start with a
three-digit line number
has been wrapped by your newsreader.

========begin file
c:\cmd\test\dnldfile.bat==================================
001. @echo off
002. if "%1"=="" goto syntax
003. if "%1"=="?" goto syntax
004. if "%1"=="/?" goto syntax
005. if "%1"=="help" goto syntax
006. if "%1"=="HELP" goto syntax
007. if "%2"=="" goto syntax
008. if "%3"=="" goto syntax
009. if "%4"=="" goto syntax
010. if "%5"=="" goto syntax
011. goto begin
012.
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
013. :syntax
014. echo.
015. echo Download a REMOTE file to your PC
016. echo.
017. echo Parameters are:
018. echo.
019. echo ^<REMOTE file^> ^<PC file^> ^<REMOTE host^> ^<userid^>
^<password^>
020. echo.
021. echo where REMOTE file is the fully-qualified file name on the
remote
022. echo host
023. echo.
024. echo REMOTE host is the IP address or name of the remote
computer
025. echo.
026. echo userid and password are valid to open FTP on the remote
host
027. echo.
028. echo If it is more convenient to do so, you can assign the REMOTE
host,
029. echo userid, and password to environment variables rather than
enter
030. echo them every time you invoke this batch file. (Change the
batch
031. echo file accordingly.)
032. echo.
033. echo example:
034. echo.
035. echo %0 pub.lib(phones) c:\temp\phones.txt 123.45.678.90 ralph
zanzibar
036. echo.
037. echo The PC path (subdirectory) must already exist
038. echo.
039. goto :EOF
040.
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
041. :begin
042. set REMOTEfile=%1
043. set PC_file=%2
044. set REMOTEhost=%3
045. set ZUserid=%4
046. set ZPassword=%5
047. set cmdfile=dnldfile
048.
049. echo>c:\temp\%cmdfile%.ftp user %ZUserid% %ZPassword%
050. echo>>c:\temp\%cmdfile%.ftp get '%REMOTEfile%' %PC_file%
051. echo>>c:\temp\%cmdfile%.ftp quit
052. echo>c:\temp\%cmdfile%.bat ^@echo off
053. echo>>c:\temp\%cmdfile%.bat %%"%%>%%"%% c:\temp\%cmdfile%.log ftp
-n
s:c:\temp\%cmdfile%.FTP
%REMOTEhost%
054. echo>>c:\temp\%cmdfile%.bat type NUL ^> c:\temp\%cmdfile%.FTP
055. echo.
056. echo Downloading file %REMOTEfile% to %PC_file%
057. call c:\temp\%cmdfile%.bat > nul
058. find "250 " c:\temp\%cmdfile%.log > NUL
059. if errorlevel 0 goto :dnldok
060. echo.
061. echo Download of file %REMOTEfile% from %REMOTEhost% has failed.
062. echo Check the following messages:
063. echo.
064. find /v "ftp>" c:\temp\%cmdfile%.log
065. type NUL > c:\temp\%cmdfile%.log
066. echo.
067. goto :EOF
068.
069. :dnldok
070. type NUL > c:\temp\%cmdfile%.log
071. goto :EOF
072.
073. :EOF
074.
========end file
c:\cmd\test\dnldfile.bat==================================


Matthew Haley

unread,
Sep 21, 1999, 3:00:00 AM9/21/99
to
Hi Phil Robyn ,

Just thought you would like to know that if your batch file is in
C:\TEMP and you run it from there, it will self destruct.

On Mon, 20 Sep 1999 14:53:08 -0700,
<<Phil Robyn>> wrote:

===================================
Matthew Haley
mhal...@homemail.com
http://www.users.uswest.net/~mrh99
===================================

Phil Robyn

unread,
Sep 21, 1999, 3:00:00 AM9/21/99
to
Matthew Haley wrote:

> Hi Phil Robyn ,
>
> Just thought you would like to know that if your batch file is in
> C:\TEMP and you run it from there, it will self destruct.
>

I never save anything that I am planning to use more than once
in the TEMP subdirectory.


0 new messages