Question : Running FTP command from a batch file

I did try to call a Batch file from VB.Net using the shell command. This works perfectly & the command from the VB.NET application is as follows:

Shell("C:\daemons\getslicer1.bat",vbNormalFocus).

The getslicer1.bat file is this :

"ftp -s:getslicer1.ftp"

This is ok too.
The ftp file which is invoked by the above bat file is :

open 192.168.0.21
hc
cd C:\STATEX
delete statex_slicer1.txt
rename statex.txt statex_slicer1.txt
get statex_slicer1.txt
quit

Which works too most of the time. When I say most of the time I mean that sometimes when the batch file is called the location where the .ftp file is searched by the .bat file is changing!!!!
So The shell command calls the getslicer1.bat file from C:\daemons and  the getslicer1.ftp file is located in the C:\ directory so it's executed however sometimes if I pause the batch file I can see that the batch command in the command line is looking to a different directory !!!
I can't understand why as nobody and nothing changed anything in NEITHER the FTP or BAT code but yet when it executes it tries to look for the ftp file in a different location.
I think that I should force the batch file to search for the fpt in a certain location.
When I did first run the getslicer1.bat file using the shell command  it looked by default in C:\ so I assumed that this is the default.
However if I click on the bat file inside the :C\daemons where it is located it will show an error (if I pause the code) as it looks for the ftp inside the C:\daemons.
So obviously the location where the batch file will look for the FTP file depends on the method it is invoked.
If invoked by shell from VB.NET looks for the ftp in the C:\ but if run locally it looks for the file in the same directory where it was initiated from.However if called by the SHELL command the location where the bat file tries to run the ftp file is chnaging based on god knows what.
Could you please help me with this?
 

Answer : Running FTP command from a batch file

It's like this:

You can run a batch file that is located ANYWHERE on your system by:

   (1) specifying it's full path along with the filename

   (2) by navigating to the directory where the batch file exists, then just refering to it by name

The difference is, the batch file will only see files currently 'Working Directory': where YOU are - not where the batch file is.

When you do a CD command on it's own, DOS returns the current working directory showing you where you are.

NOTE: Normally, because the default prompt is '$p$g', your current working directory is always shown as part of the DOS prompt. You can change this by entering the following command:

   PROMPT $g

or even:

   PROMPT %username% $+$g

In which case, you'll occasionally need to verify where you are by entering just CD on it's own (or even ECHO %cd%).

Whatever CD returns is your current working directory.

No matter where you batch file is located, if it needs to refer to any files, it will ALWAYS ONLY look in the current working directory UNLESS...

Unless you specify the file's full path as part of it's filename (so that the batch file knows where to look for the file).

Therefore, GetSlicer1.bat needs to look like this:

   ftp -s:c:\getslicer1.ftp

(if GetSlicer1.ftp is located in the c:\ directory).
Random Solutions  
 
programming4us programming4us