1.

Solve : Passing parameter to Ftp Script?

Answer»

Hi,

I am AUTOMATING an Ftp task.
Done mainly, just need to pass an parameter, which i am UNABLE to do.

What i am doing is:


ftp -s:Input_file hostname


username
password
commnad
bye

In the command i want to transfer one file.
This file will be given at the command prompt while calling that Ftp_Automate.bat so that it can be a general one.

Now how do i do this?You could create the input file on the fly from the batch file, and then call ftp.

Example:

GetFile.bat
ECHO OFF
echo open ftp.mysite.net > %temp%\ftp.data
echo bdetchevery > %temp%\ftp.data
echo mypasswd > %temp%\ftp.data
echo get %1 > %temp%\ftp.data
echo bye > %temp%\ftp.data
ftp -s:%temp%\ftp.data
erase %temp%\ftp.data

Don't forget to change the site, username, and password to whatever you want.
This file should create a file in your Tempdirectory CALLED ftp.data it will contain the script that the ftp program will input to read.  

Note the line "echo get %1 > %temp%\ftp.data". The %1 will be substituded for the first parameter on the command line, %2 is the second parameter.

Etc.

Hope this helps,

Brad D.Thanks,

But in the end i ended up with that only.

I was just thinking there must be a formal way to pass a parameter without writing so much useless echoes.  8-)Sorry, I don't think ftp has it's own parameter passing scheme

I also noticed a bug in my script, I thought i might have made the mistake after I wrote it but wasn't at my computer to check.

Each of the echo's (after the first) should have >> not just one >

GetFile.bat
ECHO OFF
echo open ftp.mysite.net > %temp%\ftp.data
echo bdetchevery >> %temp%\ftp.data
echo mypasswd >> %temp%\ftp.data
echo get %1 >> %temp%\ftp.data
echo bye >> %temp%\ftp.data
ftp -s:%temp%\ftp.data
erase %temp%\ftp.data


Otherwise only the last line gets written to the file.

If you want to use less echos you could create a text file, say callled ftp.txt and put the following into it

open ftp.mysite.net
bdetchevery
passwd

then you could use the commands

type ftp.txt > %temp%\ftp.data
echo get %1 >> %temp%\ftp.data
echo bye >> %temp%\ftp.data
ftp -s:%temp%\ftp.data
erase %temp%\ftp.data

this use's less echo's  



Discussion

No Comment Found