FTP question...

P

Paul H

If this is not the appropriate place for this question, please steer me
right. I also put this in the Vista General area, but the process will run
on an XP machine for a while. Also, the Vista version had a couple typos I
have fixed.
I hope the following is understandable by one of you batch file Guru's.
I need to automate a process that has been running manually. It goes like
this:

1. Open a DOS window.

2. Change to the folder I want to receive the file into.

3. enter "ftp ftp.blahblahblah.com".

4. When prompted as follows, enter a User ID. The following 4 lines of text
are received, after a .2 second to maybe 10 or more second wait, then
wanting a User ID to be entered.

a) Connected to ftp.blahblahblah.com.
b) 220-Microsoft FTP Service
c) 220 WARNING: Unauthorized [snip] suspected.
c(User <ftp.blahblahblah.com:<none>>:

d) abc (I have entered the User ID "abc".

5. When prompted as follows, enter the password. The following line of
text is received after a variable length delay:

a)331 Password required for abc.

b)456xyz (I have entered the password "456xyz")

6. Cause the file to be retrieved. This will be prompted for by:

a)2130-WARNING: Unauthorized [snip] suspected.
b)230 User abc logged in.
c)ftp>
d)get MyNewFile.txt (I have entered "get MyNewFile.txt")

7. end the FTP session.



It's been quite a while since I did a DOS batch file, so I need help.
My 1st guess would be:
cd \new-in
echo off
ftp ftp.blahblahblah.com
wait for the prompt (somehow watching for specific text)
echo abc
wait for the prompt (somehow watching for specific text)
echo 456xyz
echo get MyNewFile.txt
echo quit
execute a local program to process the file just received.
exit

TIA, Paul
 
P

Pegasus

Paul H said:
If this is not the appropriate place for this question, please steer me
right. I also put this in the Vista General area, but the process will
run
on an XP machine for a while. Also, the Vista version had a couple typos
I
have fixed.
I hope the following is understandable by one of you batch file Guru's.
I need to automate a process that has been running manually. It goes like
this:

1. Open a DOS window.

2. Change to the folder I want to receive the file into.

3. enter "ftp ftp.blahblahblah.com".

4. When prompted as follows, enter a User ID. The following 4 lines of
text
are received, after a .2 second to maybe 10 or more second wait, then
wanting a User ID to be entered.

a) Connected to ftp.blahblahblah.com.
b) 220-Microsoft FTP Service
c) 220 WARNING: Unauthorized [snip] suspected.
c(User <ftp.blahblahblah.com:<none>>:

d) abc (I have entered the User ID "abc".

5. When prompted as follows, enter the password. The following line of
text is received after a variable length delay:

a)331 Password required for abc.

b)456xyz (I have entered the password "456xyz")

6. Cause the file to be retrieved. This will be prompted for by:

a)2130-WARNING: Unauthorized [snip] suspected.
b)230 User abc logged in.
c)ftp>
d)get MyNewFile.txt (I have entered "get MyNewFile.txt")

7. end the FTP session.



It's been quite a while since I did a DOS batch file, so I need help.
My 1st guess would be:
cd \new-in
echo off
ftp ftp.blahblahblah.com
wait for the prompt (somehow watching for specific text)
echo abc
wait for the prompt (somehow watching for specific text)
echo 456xyz
echo get MyNewFile.txt
echo quit
execute a local program to process the file just received.
exit

TIA, Paul

Your functional description is a little unclear but perhaps you need a batch
file that will do the following:
1. Prompt you for a user name.
2. Prompt you for a password.
3. Prompt you for a file name.
4. Using ftp.exe, download the specified file from a fixed site.
5. Execute the specified file.
Correct? And what if the specified file already exists on the hard disk?
 
P

Paul H

Pegasus, you are almost correct. Except, my batch file will initiate the
process - a dialog with a remote server, via the internet. My batch file
must then interact with that remote process, responding to it's prompts.

The folder to receive the file will be empty.

My 2 main issues are:
1. How to send text to the FTP process. I believe echo is the solution, but
I'm unsure.
2. How to wait for specific test to arrive, prompting my batch file to
progress to the next step.
I hope this is possible.

==================


Your functional description is a little unclear but perhaps you need a batch
file that will do the following:
1. Prompt you for a user name.
2. Prompt you for a password.
3. Prompt you for a file name.
4. Using ftp.exe, download the specified file from a fixed site.
5. Execute the specified file.
Correct? And what if the specified file already exists on the hard disk?

===============



If this is not the appropriate place for this question, please steer me
right. I also put this in the Vista General area, but the process will run
on an XP machine for a while. Also, the Vista version had a couple typos I
have fixed.
I hope the following is understandable by one of you batch file Guru's.
I need to automate a process that has been running manually. It goes like
this:

1. Open a DOS window.

2. Change to the folder I want to receive the file into.

3. enter "ftp ftp.blahblahblah.com".

4. When prompted as follows, enter a User ID. The following 4 lines of text
are received, after a .2 second to maybe 10 or more second wait, then
wanting a User ID to be entered.

a) Connected to ftp.blahblahblah.com.
b) 220-Microsoft FTP Service
c) 220 WARNING: Unauthorized [snip] suspected.
c(User <ftp.blahblahblah.com:<none>>:

d) abc (I have entered the User ID "abc".

5. When prompted as follows, enter the password. The following line of
text is received after a variable length delay:

a)331 Password required for abc.

b)456xyz (I have entered the password "456xyz")

6. Cause the file to be retrieved. This will be prompted for by:

a)2130-WARNING: Unauthorized [snip] suspected.
b)230 User abc logged in.
c)ftp>
d)get MyNewFile.txt (I have entered "get MyNewFile.txt")

7. end the FTP session.



It's been quite a while since I did a DOS batch file, so I need help.
My 1st guess would be:
cd \new-in
echo off
ftp ftp.blahblahblah.com
wait for the prompt (somehow watching for specific text)
echo abc
wait for the prompt (somehow watching for specific text)
echo 456xyz
echo get MyNewFile.txt
echo quit
execute a local program to process the file just received.
exit

TIA, Paul
 
P

Pegasus

Paul H said:
Pegasus, you are almost correct. Except, my batch file will initiate the
process - a dialog with a remote server, via the internet. My batch file
must then interact with that remote process, responding to it's prompts.

The folder to receive the file will be empty.

My 2 main issues are:
1. How to send text to the FTP process. I believe echo is the solution,
but
I'm unsure.
2. How to wait for specific test to arrive, prompting my batch file to
progress to the next step.
I hope this is possible.

It is not possible to interact with ftp.exe in the way you think. Instead
you have to anticipate what prompts ftp.exe will throw at you, then supply
these prompts by means of a script. Try this batch file. You must adjust
Lines 2 to 6 to suit your requirements.
@echo off
set site=ftp.paul.com
set account=pat
set password=somepassword
set folder=d:\My Files
set file=SomeFile.exe
set script="%temp%\script.scr"

cd /d "%folder%"
echo> %script% %account%
echo>>%script% %password%
echo>>%script% binary
echo>>%script% get "%file%"
echo>>%script% quit
ftp -s:%Script% %site%

if exist "%file%" ("%file%") else (echo File "%file%" not found on the ftp
site)
 
P

Paul H

But what about waiting before providing the user ID and again before the
password? Too soon and it's ignored, too late and it times out.

==============


Paul H said:
Pegasus, you are almost correct. Except, my batch file will initiate the
process - a dialog with a remote server, via the internet. My batch file
must then interact with that remote process, responding to it's prompts.

The folder to receive the file will be empty.

My 2 main issues are:
1. How to send text to the FTP process. I believe echo is the solution,
but
I'm unsure.
2. How to wait for specific test to arrive, prompting my batch file to
progress to the next step.
I hope this is possible.

It is not possible to interact with ftp.exe in the way you think. Instead
you have to anticipate what prompts ftp.exe will throw at you, then supply
these prompts by means of a script. Try this batch file. You must adjust
Lines 2 to 6 to suit your requirements.
@echo off
set site=ftp.paul.com
set account=pat
set password=somepassword
set folder=d:\My Files
set file=SomeFile.exe
set script="%temp%\script.scr"

cd /d "%folder%"
echo> %script% %account%
echo>>%script% %password%
echo>>%script% binary
echo>>%script% get "%file%"
echo>>%script% quit
ftp -s:%Script% %site%

if exist "%file%" ("%file%") else (echo File "%file%" not found on the ftp
site)
 
P

Pegasus

Paul H said:
But what about waiting before providing the user ID and again before the
password? Too soon and it's ignored, too late and it times out.

I recommend you try my batch file, then post again.
 
P

Paul H

Pegasus, I should not question your advice. It absolutely worked. I
removed the final "if exists" line, because that caused the file to be
opened by notepad. ????

I can complete my task by making part of the name of the file to be
retrieved be yymmdd of the previous day. Do I have to write a program to do
this (I code COBOL (don't laugh))?

TIA, Paul



Paul H said:
But what about waiting before providing the user ID and again before the
password? Too soon and it's ignored, too late and it times out.

I recommend you try my batch file, then post again.
 
P

Pegasus

Paul H said:
Pegasus, I should not question your advice. It absolutely worked. I
removed the final "if exists" line, because that caused the file to be
opened by notepad. ????

I can complete my task by making part of the name of the file to be
retrieved be yymmdd of the previous day. Do I have to write a program to
do
this (I code COBOL (don't laugh))?

Mmh. Cobol. This goes back a long way . . .

Yes, you have to write a program to go back one day. Here are a few options:
- Cobol
- VB Script
- Batch

VB Script is easy because it has full date arithmetic capabilities. Batch
can be done but is horrible and almost incomprehensible, and therefore hard
to maintain.

If you don't want the downloaded file to be opened by notepad, use your own
command.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top