# DOS FTP using variables



## cgjoker (Aug 13, 2003)

Hi there.

Im trying to run a batch file that gets user info and passes it to a ftp command file. The ftp command file would use these variables to retrieve a file specified by the user, (i.e. the variables being passed).

Here is what I have thus far, but unfortunately, the ftp portion isn't working. Its prompting for the user id and password. I would like the entire process to be automated, with the only user intervention being the intial input variables.

*Batch File:*
@echo off

cd C:\Data_Manual

C:

set /p directory=Please enter the directory path

echo %directory% is the directory you typed

set /p filename=Please enter the filename.

echo %filename% is the file name you typed

F:\Download_from_Unix\Manual\Unix_FTPSCRIPT_file.cmd %directory% %filename%

*Command File:*
set fullpath=/NewDirectory/%1
echo %fullpath%
set filename=%2
echo %filename%

ftp 
open 10.x.x.x
userid
password
prompt
cd /%fullpath%
get %filename% C:\Data_Manual\%filename%
quit

Do I have to output the variables to a .ini file, then have the ftp command file lookup this file for this to work? Id rather not have to do this but if its the only option then I guess I must.

thanks.


----------



## zippyG (Mar 23, 2005)

I'm working on the same kind of thing and having that same prob. Did you figure it out? if so please share.


----------



## Gibble (Oct 10, 2001)

Here try this 

```
@echo OFF

REM INSTRUCTIONS

REM 1. Set the ftpascii value to a temp file name (used to store ftp commands to be run at the end of the script)
REM 2. Set destinationDir to the directory you want to change to once you connect to the ftp server

REM 3. Replace ftp.server.com with your ftp server
REM 4. Replace username with your username
REM 5. Replace password with your password

REM 6. Replace the 'commandhere' with the appropriate ftp command (make as many lines as you need)

@echo

set ftpascii="C:\temp\ftpascii.txt"
set destinationDir=/htdocs/

REM Build the ftp script.
REM We don't leave a space between the value & the > symbol because that space would be sent to the file

echo open ftp.server.com> %ftpascii%
echo username>> %ftpascii%
echo password>> %ftpascii%
echo cd %destinationDir%>> %ftpascii%
echo commandhere>> %ftpascii%
echo commandhere>> %ftpascii%
echo commandhere>> %ftpascii%
echo commandhere>> %ftpascii%
echo commandhere>> %ftpascii%
echo quit>> %ftpascii%
REM -----------------------------------

ftp -s:%ftpascii%
```


----------



## zippyG (Mar 23, 2005)

Just what I was looking for!  :up:


----------



## Gibble (Oct 10, 2001)

Glad to be of help.


----------



## cgjoker (Aug 13, 2003)

Sorry... just checked my email. My solution was very similar.

Thanks for replying to him for me Gibble.


----------

