MS DOS Batch file copy file from FTP Site

Hi,

I have no knowledge of MS DOS. However I have copied a Batch file & text file (both below) and tried adjusting it to what I require, which is simply to copy a file from an FTP site to my works G: drive. The DOS screen flicks up but does nothing. Also could someone please explain the first two lines of the Batch file?

Batch File

G:
G:\Shared\Fixed Income\Sovereign\Mark\Scheduled Tasks
ftp -s:txtFTSE.scp data.ftse.com

txtFTSE file

username
password
prompt n
cd data/gilts/gilts_constituents
get BGCO1904.csv "G:\Shared\Fixed Income\Sovereign\Mark\FTP\BGCO1904.csv" overwrite
quit

Many thanks,

Mark
mcs26Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sirbountyCommented:
Your batch file is going to basically run the ftp command, and pass it the automation script - which in your example is txtFSTSE.scp

So, the only interpretation needed from the batch file, is technically irrelevant, provided you place those comands in your ftp script file.  Those commands simply changed to the proper drive, and subsequently, the proper folder.  But that's easily handled in the script file.

I would suggest modifying it to the attached code.
Your batch file becomes a one-liner.  Simply use:

  @ftp -s:c:\Path_To_FTPScript\txtFTSE.scp

Please let us know if you need further assistance.

Here's a couple of sites to explain more on automating FTP, if you're curious.
http://support.microsoft.com/kb/96269
http://www.robvanderwoude.com/ftp.php
lcd "G:\Shared\Fixed Income\Sovereign\Mark\Scheduled Tasks\"
open data.ftse.com
username
password
prompt n
cd data/gilts/gilts_constituents
get BGCO1904.csv "G:\Shared\Fixed Income\Sovereign\Mark\FTP\BGCO1904.csv" overwrite 
quit

Open in new window

0
willettmeisterCommented:
the first line switches to the "G:" drive.
The second line should probably read cd G:\Shared\Fixed Income\Sovereign\Mark\Scheduled Tasks which will switch to the specified directory.
The third runs the ftp command with the txtfile as input using data.ftse.com and the site to ftp to.

In the textfile
first line username
second line passowrd
third line tell the ftp programs to not confirm your choices(dont prompt you)
fourth lin changes to the specified directory
fifth lines grabs the file
sixth lines quits

to troubleshoot from within windows go to start then run and type cmd then enter
that will open a command prompt
run your batch file
it should output errors from you program post them here if they dont make sense to you.
0
pine_nel1Commented:
Hi mcs26,

Change to G drive
Execute: ftp to data.ftse.com and the run script (list of ftp commands) (G:\) txtFTSE.scp

Thanks

Pine
0
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

mcs26Author Commented:
Thanks SirBounty for replying.  I have just changed my files to what you said it still however does not copy the file from the FTP site. It says error opening script file G:\Shared\Fixed

So I am guessing it does not like the space in the folder name. Only thing is I cannot change the folder name as I do not have permissions. Any ideas?

Thanks again

Mark
0
sirbountyCommented:
Is the script located here: G:\Shared\Fixed Income\Sovereign\Mark\Scheduled Tasks?

If so, then you need to ensure that entire path is enclosed in quotes (as in my example above).
Some internal commands will work without them, but ftp will not.  The outer quotes are needed since Fixed Income has a space in between it...
Try that and let me know.
0
mcs26Author Commented:
Yeah the script is located in G:\Shared\Fixed Income\Sovereign\Mark\Scheduled Tasks. I have quotes around that in the script file not the batch file though.

Still no luck though. My script file looks like this,

lcd "G:\Shared\Fixed Income\Sovereign\Mark\Scheduled Tasks\"
open data.ftse.com
username
password
prompt n
cd data/gilts/gilts_constituents
get BGCO1904.csv "G:\Shared\Fixed Income\Sovereign\Mark\FTP\BGCO1904.csv" overwrite
quit
0
sirbountyCommented:
So your batch file should read:

@ftp -s: "G:\Shared\Fixed Income\Sovereign\Mark\Scheduled Tasks\txtFTSE.scp"

the script should read:

lcd "G:\Shared\Fixed Income\Sovereign\Mark\FTP"
open data.ftse.com
username
password
prompt n
cd data/gilts/gilts_constituents
get BGCO1904.csv overwrite 
quit

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BillDLCommented:
Hi mcs26

First of all, unless you are running an operating system of Windows 98 or older, it isn't really "MS-DOS".  Those older operating systems used "Command.com" as their command line program.  Windows 2000 and onwards use "CMD.EXE" which really runs within Windows and emulates MS-DOS.

OK, in Windows XP the FTP.EXE program file normally resides in a system folder:
C:\WINDOWS\system32\ftp.exe
and so can usually be called at any time without specifying a path to it.

In your example batch file, whoever wrote it obviously has FTP.EXE on a G:\ shared drive in the folder:
G:\Shared\Fixed Income\Sovereign\Mark\Scheduled Tasks

To change from the drive that shows as the "Current Directory" when you open a new "Command Window" (ie. what shows as the "Prompt>" you just place D:  E:  F:  G:  or whatever drive you wish to change to, on a line by itself.  The prompt would then show that the current working directory has moved to the other drive.  Here's the actual output showing me doing this in a command window manually and changing from the C:\Support folder to the J:\ Drive:

C:\Support>J:

J:\>

To then move from the Root of that drive into some folder, you would use the   CD    or    CHDIR   command (not, generally "DOS" doesn't worry if it's uppercase or lowercase), like this where I want to move from the root of J:\  to the folder "J:\Support Tools".  Here is the output to the screen of me executing this "Change Directory" command:

J:\>cd "support tools"

J:\Support Tools>

Note that I double-quoted the folder name because it has a space in it.  The Command Line in recent versions of Windows usually doesn't worry about spaces, but in some instances a space can cause the command being executed to treat each space-separated part of the parameter (in this case a folder name) as different parts and fail.  To avoid this you double-quote strings with spaces to have them treated as literal strings.

In Windows XP and onwards the   CD   command received an extra /D "switch" whereby you can simultaneously change to another Drive AND into a Folder on that drive, eg.

CD /D "J:\Support Tools"

I would suggest that the 2nd line of your batch file is wrong.  It is just quoting a directory path with no instruction eg. go there, or echo that path to the screen, or execute a file in that path.  The two commands should be:

G:
cd G:\Shared\Fixed Income\Sovereign\Mark\Scheduled Tasks

or

cd /d G:\Shared\Fixed Income\Sovereign\Mark\Scheduled Tasks

The FTP.EXE command could actually have been run without changing into the folder containing it, like this:

G:\Shared\Fixed Income\Sovereign\Mark\Scheduled Tasks\FTP.EXE

However, there are benefits with physically moving into a drive and folder to execute commands.  You don't have to keep using long folder names to tell it where to find other files or where to create them, because it will look for them or create them in your "Current Directory".

OK, the FTP.EXE program is intended to be either interactive (ie. it prompts for your input in a command window at each step) or automated using anticipated "answers" supplied in readiness from within the batch file or from another "answer file".  If being run manually it will remain active until you type QUIT, where it will exit FTP and return to the command prompt again.

The   FTP.EXE -S:FileName   switch is specifying a text-based file that contains FTP commands. These commands will be read from that file and run automatically by FTP.EXE.

So, the FTP launch command in your batch file:

ftp -s:txtFTSE.scp data.ftse.com

is telling it to use FTP instructions from:
G:\Shared\Fixed Income\Sovereign\Mark\Scheduled Tasks\txtFTSE.scp
and to connect with the HOST:  "data.ftse.com"

The contents of the instruction file "txtFTSE.scp" have to be in a particular order and syntax to automate what would normally be entered interactively, which is where the FTP Sub-Commands come in.

This is the command line syntax for the FTP command:
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ftp.mspx

and this explains the FTP Sub-Commands, as you have in your *.scp file:
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ftp__subcommands.mspx

Your *.SCP file:
username
password
prompt n
cd data/gilts/gilts_constituents
get BGCO1904.csv "G:\Shared\Fixed Income\Sovereign\Mark\FTP\BGCO1904.csv" overwrite
quit

A piece at a time:
UserName and Password are self-explanatory.  Placed on separate lines they are read and supplied as needed.
The other way from the command line would be:
user UserName [Password] [Account]

PROMPT is enabled by default, and would await your input when transferring multiple files, so it is disabled by making it   Prompt n

cd data/gilts/gilts_constituents
tells it to change directory from:
data.ftse.com
to
cd data.ftse.com/data/gilts/gilts_constituents
on the remote computer.

The GET sub-command uses the syntax:
get "RemoteFileame" "ToLocalFileName"

So, in your case it is getting:
/data/gilts/gilts_constituents/BGCO1904.csv
from the local computer and copying it to the local computer's:
"G:\Shared\Fixed Income\Sovereign\Mark\FTP\"
folder using the same file name.  The "overwrite" at the end just tells it to overwrite an existing file of that name on the local computer if found, and do so without prompting.

Finally the QUIT command must be at the end of your answer file or you get stuck in FTP.

Note, for multiple files use the MGET sub-command.

I hope this explains it.

Bill
0
BillDLCommented:
Whoops, when I last looked nobody had commented.  I went to make some tea, rattled out an answer, hit the Submit button, and it now looks like I have plagiarised and/or reiterated comments made while I was making tea and typing as fast as I could.  Sorry ;-)
0
sirbountyCommented:
No worries here Bill.  ;^)
Enjoy your tea.
0
mcs26Author Commented:
Hi Bill & SirBounty,

thanks for the explantion!
My batch file looks like the line below but still no luck. I am going to e-mail the data provider becuase I cannot really what is wrong?

@ftp -s: "G:\Shared\Fixed Income\Sovereign\Mark\Scheduled Tasks\txtFTSE.scp"
0
mcs26Author Commented:
The error message is still saying "Error opening script file G:\Shared\Fixed Income\Sovereign\Mark\Scheduled Tasks\txtFTSE.scp."
0
sirbountyCommented:
try removing that space after s:...should read:

@ftp -s:"G:\Shared\Fixed Income\Sovereign\Mark\Scheduled Tasks\txtFTSE.scp"

Failing that, you can try with this slight modification:

@cd /d "G:\Shared\Fixed Income\Sovereign\Mark\Scheduled Tasks\txtFTSE.scp"
@ftp -s:txtFTSE.scp
0
sirbountyCommented:
You're certain that the file exists as txtFTSE.scp?
0
mcs26Author Commented:
Yeah the file exists, have doubled checked it. Still no luck though.
0
BillDLCommented:
Check for line breaks in the *.SCP file.  If viewing it in Windows Notepad with word-wrap on it may have created a new line like this:

@cd /d "G:\Shared\Fixed Income\Sovereign\Mark\Scheduled
Tasks\txtFTSE.scp"

instead of this:

@cd /d "G:\Shared\Fixed Income\Sovereign\Mark\Scheduled Tasks\txtFTSE.scp"

Copy and paste them both to Notepad and uncheck word-wrap to see.
0
mcs26Author Commented:
Hi Bill,

Just opened the file and it already has word-wrap unchecked, otherwise like you with it on it does create a new line.

Thanks,
0
sirbountyCommented:
Hmm - let's try depending on 8.3 conversion then (somewhat presumptuous, but worth a shot)
Spaces should no longer be a factor...

Batch file:
  @ftp -s:G:\Shared\FixedI~1\Sovereign\Mark\Schedu~1\txtFTSE.scp
lcd G:\Shared\FixedI~1\Sovereign\Mark\FTP
open data.ftse.com
username
password
prompt n
cd data/gilts/gilts_constituents
get BGCO1904.csv overwrite 
quit

Open in new window

0
BillDLCommented:
Are you just fetching one file, and the same file, on a regular basis?

If so, you can possibly avoid all the messing around by using a simpler standalone program file named "URL2File":
http://www.chami.com/free/url2file_wincon.html
It is part of the "HTML-Kit Tools" package:
http://www.chami.com/

Under the "Download / Install" section of the "/url2file_wincon.html" page you will see the links for an Installer version and a ZIP file containing the standalone files (URL2FILE.EXE and Readme.txt).  I suggest just using the standalone EXE.

Usage is show a bit further down the download page and there is another "Tip" page showing usage in a batch file:
http://www.chami.com/tips/windows/062598W.html

I prefer this for simple single file fetching to FTP.EXE, but you need to specify the FTP Protocol, eg. target URL, eg:
ftp://data.ftse.com/data/gilts/gilts_constituents/BGCO1904.csv
0
BillDLCommented:
Hmmm.  I see that you can also enter (on login) via http://data.ftse.com/HttpPull/login.jsp
0
mcs26Author Commented:
Hi Bill & SirBounty,

Firstly thanks for helping me.

Sadly I'am not allowed (or able) to download anything onto my computer, company is very strict, which is a pain in neck! I like the idea of entering the login although when we had the account setup I was warned by the data provider that sometimes you will have to log in twice, they have some bug there end by the sounds of it!

I have tried the new code you have writting with no luck, I have written to the data provider to see if it is an error their side. Will let you know what they come back with when they do get back to me.

Thanks,
0
sirbountyCommented:
Please open a cmd prompt (Start->Run->cmd <Enter>) and test this manually, step-by-step...
The same commands should work for you one line at a time.  Check if any come back with an error when it's not automated:

ftp <enter>
lcd G:\Shared\FixedI~1\Sovereign\Mark\FTP <enter> (success?)
open data.ftse.com <enter>
username <enter>
password <enter> (connected?)
prompt n <enter> (though this is irrelevant when stepping through)
cd data/gilts/gilts_constituents <enter> (success?)
get BGCO1904.csv overwrite <enter> (success?)
bye <enter>
0
mcs26Author Commented:
I will try it on my home computer (and make the adjustments to the file locations) after work, as our IT are a bit control freakish, we do not have the option of Run from out Start menus.
0
sirbountyCommented:
Any update?
0
mcs26Author Commented:
Hi Sirbounty,

I am going to chance the data provider up again today & soon as I hear anything will let you know.

Thanks
0
sirbountyCommented:
Recommend split http:#31272662 and http:#31273324
Automated script was provided, as was Bill's most excellent description of the commands and how they work.  I believe the author got what they were after...
0
BillDLCommented:
Thak you SirBounty and Vee_Mod
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
File Sharing Software

From novice to tech pro — start learning today.