[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Running FTP command from a batch file

Posted on 2010-08-19
10
Medium Priority
?
1,554 Views
Last Modified: 2013-12-09
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?
 
0
Comment
Question by:Latzi_Marian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
  • +1
10 Comments
 
LVL 60

Assisted Solution

by:HainKurt
HainKurt earned 300 total points
ID: 33481244
use full path for ftp file and you are good to go

"ftp -s:getslicer1.ftp"
-->
"ftp -s:drive:\full\path\to\getslicer1.ftp"
0
 

Author Comment

by:Latzi_Marian
ID: 33481292
Thanx for your answer. I will try this right now however  the question is why the SHELL command will change the directory where the bat file is "looking" for the ftp file?
0
 
LVL 16

Accepted Solution

by:
t0t0 earned 900 total points
ID: 33481459
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).
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 16

Expert Comment

by:t0t0
ID: 33481465
Sorry, I meant:

   The difference is, the batch file will only see files in the current 'Working Directory' (where YOU are - not where the batch file is).
0
 
LVL 60

Expert Comment

by:HainKurt
ID: 33481494
where is your executable located? maybe it is getting the running path from operating system, maybe last used command path...
0
 

Author Comment

by:Latzi_Marian
ID: 33481869
The executable is in a different directory yet again. It is fixed now as I set the path in the batch file but still don't quite understand what switched the path. Nothing was running on the PC when this happened.
0
 
LVL 60

Expert Comment

by:HainKurt
ID: 33481902
if it is fixed now, dont worry be happy ;)
0
 
LVL 43

Assisted Solution

by:Steve Knight
Steve Knight earned 300 total points
ID: 33482770
BTW if you want it to always pick up from the path where the batch file is stored even if the working directory is something else then you get the directory of the batch file using:

%~dp0

So for instance in your batch file

@echo off
echo The drive was %cd%
cd /d "%~dp0"
echo Now it is the batch file ( %~nx0) directory %cd%

Or just add the path to the script file on the ftp line.
Or use a different method to make the ftp scrript on the fly (the all one one file method from here:)

http://scripts.dragon-it.co.uk/links/batch-ftp-scripting?OpenDocument

Steve
0
 

Author Closing Comment

by:Latzi_Marian
ID: 33484339
Thank you all guys.it's all tested and working.It's pretty clear what happened and why.Thanx again.
0
 
LVL 16

Expert Comment

by:t0t0
ID: 33488588
Thank you. Glad you got it sorted. Easy as pie and chipes isn't it?
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the past decade, as Internet security has become a chief concern of IT professionals, one of the most common questions administrators and users ask is, “Which is more secure, SFTP or FTPS?” In short, both file transfer protocols offer a high…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question