difference between Shell.run and Shell.exec 
Author Message
 difference between Shell.run and Shell.exec

I have had a WSH script successfully running for over a year.

In this script a large number of ftp jobs are run using a shell.run command
and the results monitored for success or failure.

viz:

shell.run  ("%comspec% /C c:\WINNT\system32\ftp.exe -n -s:" & FtpScriptFile
& " > " & FtpLogFile)

Typically the FtpScriptFile contains either a single "Put","Get" or "ls"
command.

an example follows:
-----------------------
open TEST
user USERNAME PASSWORD
cd 1/2/3
ls datafile.txt
quit
-------------------------

Our security people have inserted a NAT router between the Client and the
Server and now intermittantly the ftp process has started to hang up. So I
am trying to change the script to monitor the status of the "ftp process"

viz:
set ftpJob = shl.exec("%comspec% /C c:\WINNT\system32\ftp.exe -n -s:" &
FtpScriptFile & " > " & FtpLogFile)
wscript.sleep(1)
count =0
while ftpjob.status = "0"  and count < 10000
    wscript.sleep(1000)
    count = count + 1
wend
if ftpjob.status =0 then
' ftp hung up!
    ftpjob.teminate
    wscript.quit
 end if
' finished ftp ok

This all seems to work OK,  However I have found a side effect that I can
not explain which might force me to rewrite the whole rest of the script.

Previously using Shell.run the FtpLogFile would contain (for example):
----------------------------------------------------------
ftp> Connected to TEST.local.
open TEST
220 TEST Microsoft FTP Service (Version 5.0).
ftp> user USERNAME  PASSWORD
331 Password required for USERNAME
230 User USERNAME logged in.
ftp> cd 1/2/3
250 CWD command successful.
ftp> ls datafile.txt
200 PORT command successful.
150 Opening ASCII mode data connection for file list.
datafile.txt
226 Transfer complete.
ftp: 13 bytes received in 0.00Seconds 13000.00Kbytes/sec.
ftp> quit
221 Goodbye
--------------------------------------------------------------

However using shell.exec the FtpLogFile contains (for example):
-----------------------------------------------------
datafile.txt

open TEST
user USERNAME  PASSWORD
cd 1/2/3
ls datafile.txt
quit
----------------------------------------------------------------

Can anyone expalin to me why:

1) Some of the output that I expect to see in the logfile is missing.
2) All the output appears before what is effectively the input from the
FtpScriptFile

Thanks in advance.

Gordon Brown



Tue, 23 Aug 2005 23:54:26 GMT  
 difference between Shell.run and Shell.exec

Quote:
> I have had a WSH script successfully running for over a year.

> In this script a large number of ftp jobs are run using a shell.run
> command and the results monitored for success or failure.

> viz:

> shell.run  ("%comspec% /C c:\WINNT\system32\ftp.exe -n -s:" &
> FtpScriptFile & " > " & FtpLogFile)

> Typically the FtpScriptFile contains either a single "Put","Get" or
> "ls" command.

> an example follows:
> -----------------------
> open TEST
> user USERNAME PASSWORD
> cd 1/2/3
> ls datafile.txt
> quit
> -------------------------

> Our security people have inserted a NAT router between the Client and
> the Server and now intermittantly the ftp process has started to hang
> up. So I am trying to change the script to monitor the status of the
> "ftp process"

I can't help with the main portion of your question, but for a description of
why FTP will often fail when working behind a NAT router, see the following:

http://slacksite.com/other/ftp.html

You need to operate in "passive" rather than "active" mode in order to
(hopefully) ensure success. A quick search
(http://www.shmoo.com/mail/fw1/jul01/msg00030.shtml) indicates that the MS ftp
client does not support passive mode, but you (or whatever minions are enslaved
to you =) should be able to find many third party solutions that do.

HTH, and feel free to reimburse me from the treasury (NOT) if you found this
info helpful.



Wed, 24 Aug 2005 02:53:46 GMT  
 difference between Shell.run and Shell.exec

Quote:
> (hopefully) ensure success. A quick search
> (http://www.shmoo.com/mail/fw1/jul01/msg00030.shtml) indicates that the MS
ftp
> client does not support passive mode, but you (or whatever minions are
enslaved
> to you =) should be able to find many third party solutions that do.

Then it's incorrect:
literal pasv


Fri, 26 Aug 2005 12:29:43 GMT  
 difference between Shell.run and Shell.exec

Quote:



>> (hopefully) ensure success. A quick search
>> (http://www.shmoo.com/mail/fw1/jul01/msg00030.shtml) indicates that
>> the MS ftp client does not support passive mode, but you (or
>> whatever minions are enslaved to you =) should be able to find many
>> third party solutions that do.

> Then it's incorrect:
> literal pasv

Ahh - then that info was either out of date or just plain wrong. Thanks
for the update.


Fri, 26 Aug 2005 13:06:17 GMT  
 difference between Shell.run and Shell.exec


Quote:


> > (hopefully) ensure success. A quick search
> > (http://www.shmoo.com/mail/fw1/jul01/msg00030.shtml) indicates that the
MS
> ftp
> > client does not support passive mode, but you (or whatever minions are
> enslaved
> > to you =) should be able to find many third party solutions that do.

> Then it's incorrect:
> literal pasv

While a LITERAL PASV command will inform the server to fall in a open a
passive port and inform the client of its address.

This is NOT the same as  an ftp client that has a "passive" mode.

With such an ftp-client that understands passive mode  the user can  then
issue simple "put", "get" or "dir" commands and the ftp client will issue
all the correct underlying commands such as STOR, LIST, PORT, RETR in such
way to  cause the network connection to be made from a high-numbered TCP IP
port on the client to a high-numbered TCP IP port on server.

This has distinct  advantages when making an outbound ftp connection through
a firewall to a server on the Internet.

Although it MAYbe  possible to use "literal" and "quote" commands with the
M$ ftp client it is hellish difficult.  And  several days of trying I have
yet to successfully make the M$ ftp client initiate the data connection to a
server in Passive Mode.



Tue, 30 Aug 2005 01:40:49 GMT  
 difference between Shell.run and Shell.exec

Quote:

> While a LITERAL PASV command will inform the server to fall in a open
> a passive port and inform the client of its address.

> This is NOT the same as  an ftp client that has a "passive" mode.

> With such an ftp-client that understands passive mode  the user can
> then issue simple "put", "get" or "dir" commands and the ftp client
> will issue all the correct underlying commands such as STOR, LIST,
> PORT, RETR in such way to  cause the network connection to be made
> from a high-numbered TCP IP port on the client to a high-numbered TCP
> IP port on server.

> This has distinct  advantages when making an outbound ftp connection
> through a firewall to a server on the Internet.

> Although it MAYbe  possible to use "literal" and "quote" commands
> with the M$ ftp client it is hellish difficult.  And  several days of
> trying I have yet to successfully make the M$ ftp client initiate the
> data connection to a server in Passive Mode.

Interesting. If you've managed to get your original problem solved, or at least
handled the FTP client issues, I'd appreciate it if you could post a brief
description of the solution. TIA


Tue, 30 Aug 2005 01:55:13 GMT  
 difference between Shell.run and Shell.exec


Quote:
> Interesting. If you've managed to get your original problem solved, or at
least
>handled the FTP client issues, I'd appreciate it if you could post a brief
>description of the solution. TIA

Sorry, I haven't got anywhere in solving my problem! In fact I have now got
two problems:

1) the M$ Ftp client behave differently under  SHELL.EXEC  and SHELL.RUN

 I still can not understand why the M$ ftp client produces different output
when executed with a shell.exec as opposed to a shell.run.

With shell.run the output contains all the things that appear on the screen
when executed from a "Cmd"    shell by hand.
With shell.execute the output does not contain any "messages".  For example
if you run by hand and issue an "open server.domain.com" command in response
you see:

Connected to server.domain.com.
220 server Microsoft FTP Service (version 4.0)

Since this message disappears  I can not detect the type of server to which
I have connected.
It is important for my script to execute different code dependent on the
type of server!

I do not even see a command prompt viz "ftp>" in the stdout.  In response to
some commands NO OUTPUT at all appears so if I issue a try
"string=execboj.stdout.readline"  the program hangs.

I was originally trying to use a Shell.Exec instead of a Shell.run in order
to put my script into a loop waiting either for the execobj.status to
indicate the ftp run had finished or to be able to increment a counter in
order to give up and terminate the job after a time.

2) The MICROSOFT ftp client DOES NOT support PASSIVE MODE

I am unable to make the M$ ftp client operate in a "Passive mode" (see
http://slacksite.com/other/ftp.html#intro for an explaination of what I mean
by the term).
 I have succeded in using the M$ ftp client to do drive a ftp transfer
between two M$ ftp servers. This involves using a "lieteral PASV" command
inorder to switch one of the ftp servers into what M$ call a "passive" mode.
However  there does not appear to be ANY command that I can issue to the M$
ftp client in order to get the M$ ftp client to initiate the data
connection to the Ftp Server.  A "quote  port xxx,xxx,xxx,xxx,xxx,xxx"
using the IP address and  port number  that the server announced in response
to the "literal PASV" command is rejected as invlaid.  However this
technique worked when  linking ftp server to ftp server.

My boss didn't like the suggestion that we should use a different ftp
client. He saw the task (and cost of licencing) as prohibitive as we have
11000 workstations to upgrade. He feels he already pays M$ enough and it is
obviously my fault that I can't make M$ products work...........

regards  gordon



Tue, 30 Aug 2005 19:35:56 GMT  
 difference between Shell.run and Shell.exec

Quote:
> Sorry, I haven't got anywhere in solving my problem! In fact I have
> now got two problems:

> 1) the M$ Ftp client behave differently under  SHELL.EXEC  and
> SHELL.RUN

> 2) The MICROSOFT ftp client DOES NOT support PASSIVE MODE

> I am unable to make the M$ ftp client operate in a "Passive mode" (see
> http://slacksite.com/other/ftp.html#intro for an explaination of what
> I mean by the term).
>  I have succeded in using the M$ ftp client to do drive a ftp transfer
> between two M$ ftp servers. This involves using a "lieteral PASV"
> command inorder to switch one of the ftp servers into what M$ call a
> "passive" mode. However  there does not appear to be ANY command that
> I can issue to the M$ ftp client in order to get the M$ ftp client to
> initiate the data connection to the Ftp Server.  A "quote  port
> xxx,xxx,xxx,xxx,xxx,xxx" using the IP address and  port number  that
> the server announced in response to the "literal PASV" command is
> rejected as invlaid.  However this technique worked when  linking ftp
> server to ftp server.

> My boss didn't like the suggestion that we should use a different ftp
> client. He saw the task (and cost of licencing) as prohibitive as we
> have 11000 workstations to upgrade. He feels he already pays M$
> enough and it is obviously my fault that I can't make M$ products
> work...........

Yuck - you have my sympathies. I wish I could offer some more concrete
assistance, but that's about the extent of my knowledge. Is there any way you
could set up a single linux box somewhere and use that to coordinate the ftp
activities? =)


Wed, 31 Aug 2005 01:01:53 GMT  
 difference between Shell.run and Shell.exec
"The Chancellor of the Exchequer \(NOT\)" > With shell.run the output
contains all the things that appear on the screen
Quote:
> I do not even see a command prompt viz "ftp>" in the stdout.  In response to
> some commands NO OUTPUT at all appears so if I issue a try
> "string=execboj.stdout.readline"  the program hangs.

Try this:

Option Explicit
Dim cLine
Dim oShell
' Put a VERBOSE command at the top of the FTP script.
' Then you can use StdOut.ReadLine() to see the results of each ftp
command.

Dim oInet
Dim oExec

Set oInet = Wscript.CreateObject("InetCtls.Inet")
Set oShell = Wscript.CreateObject("WScript.Shell")

SET oExec = oShell.Exec("FTP.EXE -s:c:\VBScript\inetFtp.scr")

Do While oExec.Status = 0
    '
Loop

Do While Not oExec.StdOut.AtEndOfStream
    cLine = oExec.StdOut.ReadLine()
    oShell.Popup cLine
Loop



Sun, 18 Sep 2005 06:34:48 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. WSH 5.6 Beta - Shell.Exec

2. Shell.Exec

3. Using Scripting.Shell Exec command to capture the results of a SFTP ls command

4. Launching an exec from a client script using shell

5. Wscript.Shell Exec method

6. FTP Shell.Exec

7. wscript.shell.exec STDOUT / ReadAll size limit?

8. WSH 5.6 beta - Shell.Exec

9. Shell.Application.Count or Shell.Application.Contents.Count

10. Shell script - closing shell screen

11. shell.Help and shell.Windows ???

12. shell.Help and shell.Windows ???

 

 
Powered by phpBB® Forum Software