run dos command asp


R

René

Hello group,

I have a question about a script i use. The function of the script is to
dynamically write an ftp script and execute this with dos ftp.exe . This
script always worked on a Windows 2000 pro workstation. Now i have moved it
to a Windows XP pro workstation it writes the ftp command file but the
command doesn't execute anymore. I've tried everything I could think of but
no result at all. Could someone please help me with this or give me some
clues? below the asp page i use..

Thanks in advance!

<%@ Language=VBScript %>
<!--#include file="../../Connections/FTP.asp" -->
<%
' FTP via ASP without using 3rd-party components
' Ben Meghreblian 15th Jan 2002
' benmeg at benmeg dot com / http://benmeg.com
'
' This script assumes the file to be FTP'ed is in the same directory as this
script.
' It should be obvious how to change this (*hint* change the lcd line)
' You may specify a wildcard in ftp_files_to_put (e.g. *.txt)
Dim objFSO, objTextFile, oScript, oScriptNet, oFileSys, oFile, strCMD,
strTempFile, strCommandResult
Dim ftp_address, ftp_username, ftp_password, ftp_physical_path,
ftp_files_to_put

' Edit these variables to match your specifications
ftp_address = request.QueryString("host")
ftp_username = request.QueryString("gebruikersnaam")
ftp_password = request.QueryString("wachtwoord")
ftp_remote_directory = "" ' Leave blank if uploading to root directory
ftp_files_to_put = chr(34)& request.QueryString("bestandsNaam")&chr(34)
LocalFolder = UploadPath & request.QueryString("gebruikersnaam")


On Error Resume Next
Set oScript = wscript.CreateObject("WSCRIPT.SHELL")
Set oFileSys = Server.CreateObject("Scripting.FileSystemObject")
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
' Build our ftp-commands file
Set objTextFile =
objFSO.CreateTextFile(Server.MapPath(request.QueryString("gebruikersnaam")&"
..ftp"))
objTextFile.WriteLine "lcd " & LocalFolder
objTextFile.WriteLine "open " & ftp_address
objTextFile.WriteLine ftp_username
objTextFile.WriteLine ftp_password

' Check to see if we need to issue a 'cd' command
If ftp_remote_directory <> "" Then
objTextFile.WriteLine "cd " & ftp_remote_directory
End If

objTextFile.WriteLine "prompt"

' If the file(s) is/are binary (i.e. .jpg, .mdb, etc..), uncomment the
following line' objTextFile.WriteLine "binary"
' If there are multiple files to put, we need to use the command 'mput',
instead of 'put'
If Instr(1, ftp_files_to_put, "*",1) Then
objTextFile.WriteLine "mput " & ftp_files_to_put
Else
objTextFile.WriteLine "put " & ftp_files_to_put
End If
objTextFile.WriteLine "bye"
objTextFile.Close
Set objTextFile = Nothing
' Use cmd.exe to run ftp.exe, parsing our newly created command file
strCMD = "ftp.exe -s:" &
Server.MapPath(request.QueryString("gebruikersnaam")&".ftp")
NetSendCMD ="net.exe send 10.0.1.21 Gebruiker op werkstation "&
request.ServerVariables("REMOTE_ADDR") & " heeft een foutmelding ontvangen.
Onder gebruikersaccount "&request.QueryString("gebruikersnaam")&". "
strTempFile = "C:\" & oFileSys.GetTempName( )
' Pipe output from cmd.exe to a temporary file (Not :| Steve)

oScript.Run ("D:\vbscripts\test.vbs")
call oScript.Run ("%comspec% /c " & strCMD & " > " & strTempFile, 1, True)

Set oFile = oFileSys.OpenTextFile (strTempFile, 1, False, 0)

On Error Resume Next
' Grab output from temporary file
strCommandResult = "<html><head>" & vbcrlf
strCommandResult = StrCommandResult & "<link
rel="&chr(34)&"StyleSheet"&chr(34)&"
href="&chr(34)&"../style.css"&chr(34)&"type="&chr(34)&"text/css"&chr(34)&"me
dia="&chr(34)&"all"&chr(34)&">" &vbcrlf
strCommandResult = StrCommandResult & "</head><body>" & vbcrlf
strCommandResult = StrCommandResult & oFile.ReadAll
strCommandResult = StrCommandResult & "</body></html>" &vbcrlf
oFile.Close
' Delete the temporary & ftp-command files
'Call oFileSys.DeleteFile( strTempFile, True )
'Call objFSO.DeleteFile(
Server.MapPath(request.QueryString("gebruikersnaam")&".ftp"), True )
Set oFileSys = Nothing
Set objFSO = Nothing
' Print result of FTP session to screen
StrSearch = split (strCommandResult,vbcrlf)
'response.Write(StrTempFile.readall)
FOR i = 0 TO Ubound(strSearch) -1

Melding = Split(strsearch(i)," ")
For j = 0 TO Ubound(Melding) -1
IF ErrorSend <> "1" THEN

IF Trim(Melding(j)) = "226" THEN
StatusMelding = "<font
color="&succesMeldingKleur&"><center><strong>"&SuccesMelding&"</center></str
ong></font><br>"
END IF

IF Trim(Melding(j)) = "421" THEN
StatusMelding = "<font
color="&FoutMeldingKleur&"><center><strong>"&FoutUploadMelding&"</center></s
trong></font><br>"
NetSendCMD = NetSendCmd & "Bestand upload fout"
Call oScript.Run ("cmd.exe /c " & NetSendCMD, 0, True)
ErrorSend = "1"
END IF

IF Trim(Melding(j)) = "530" THEN
StatusMelding = "<font
color="&FoutMeldingKleur&"><center><strong>"&FoutLoginMelding&"</center></st
rong></font><br>"
NetSendCMD = NetSendCmd & "Gebruikernaam of wachtwoord verkeerd"
Call oScript.Run ("cmd.exe /c " & NetSendCMD, 0, True)
ErrorSend = "1"
END IF
END IF
J = J +1
NEXT
NEXT
%>
<html>
<head>
<title>Untitled Document</title>
<link rel="StyleSheet" href="../style_ftp.css" type="text/css" media="all">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<% IF session("admin") = "1" THEN %>
<meta http-equiv="refresh"
content="100;URL=../FTPAccounts/admin_list_ftpaccounts_form.asp?statusmeldin
g=<%=(statusmelding)%>&Gebruikersnaam=<%=request.QueryString("gebruikersnaam
")%>">
<%END IF%>
<% IF session("user") = "1" THEN %>
<meta http-equiv="refresh"
content="100;URL=../FTPAccounts/public_list_ftpaccounts_form.asp?statusmeldi
ng=<%=(statusmelding)%>&Gebruikersnaam=<%=request.QueryString("gebruikersnaa
m")%>">
<%END IF%>
<% IF session("customer") = "1" THEN %>
<meta http-equiv="refresh"
content="100;URL=../FTPAccounts/customer_list_ftpaccounts_form.asp?statusmel
ding=<%=(statusmelding)%>&Gebruikersnaam=<%=request.QueryString("gebruikersn
aam")%>">
<%END IF%>

</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"
scroll="no">
<table width="100%" height="100%" border="0" align="center" cellpadding="0"
cellspacing="0">
<tr>
<td bgcolor="#6699CC"><table width="649" height="387" border="0"
align="center" cellpadding="0" cellspacing="0"
background="../../Gfx/DKL.jpg" bgcolor="#669999">
<tr>
<td><table width="100%" border="0" cellspacing="0"
cellpadding="0">
<tr>
<td width="41%">&nbsp;</td>
<td width="59%"><%=StatusMelding%><%=strcmd%></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
<%session("admin") = "0"%>

Thanks in advance
 
Ad

Advertisements

R

Ray Costanzo [MVP]

i) Whenever you're debugging, be sure to comment out any ON ERROR RESUME
NEXT lines.

On this line:
call oScript.Run ("%comspec% /c " & strCMD & " > " & strTempFile, 1, True)

Try changing it to:
'''call oScript.Run ("%comspec% /c " & strCMD & " > " & strTempFile, 1,
True)
RESPONSE.WRITE STRCMD
RESPONSE.END

What is the value of your strCmd variable? And what then happens when you
copy and paste it into a command prompt and manually execute it?

It's likely to be a firewall issue, especially if you've installed SP2 on
your XP machine.

Ray at work
 

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