tags:

views:

50

answers:

2

I am trying to use c# in .net to run dos commands to ftp a a file. Technically, it calls a BAT file which calls a CMD file which executes the DOS code. It was up to the CMD file. The CMD fiel will work if I hardcode the path, but I need to dynamically specify the path of the file.

BAT File...

ftp.exe -s:%~dp0\mycmdfile.cmd

And in the cmd file...

open <my ost>
<my user name>
<my pw>
quote site cyl pri=1 sec=1 lrecl=1786 blksize=0 recfm=fb retpd=30
put <here is where I need the dynamic path> + localfilename remotefilename

quit

A: 

You can pass in arguments to a batch files. If memory serves me right, you pass them in by putting them after the call to the batch file and using space delimiters (e.g. C:\mycmd.bat Var1 Var2). You can then use those to reconstruct your file path.

Zachary
+1  A: 

I would add to Zachary that you can refer to command line vars inside bat with %1, %2, and so on.

%~dp0 syntax is only available from Windows 2000 (if I remember it right). To refer to files from another directory just change to a directory just cd to that directory and then invoke command from it.

Fernando Miguélez