run dos command asp

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • René

    run dos command asp

    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=VBScri pt %>
    <!--#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_pu t (e.g. *.txt)
    Dim objFSO, objTextFile, oScript, oScriptNet, oFileSys, oFile, strCMD,
    strTempFile, strCommandResul t
    Dim ftp_address, ftp_username, ftp_password, ftp_physical_pa th,
    ftp_files_to_pu t

    ' Edit these variables to match your specifications
    ftp_address = request.QuerySt ring("host")
    ftp_username = request.QuerySt ring("gebruiker snaam")
    ftp_password = request.QuerySt ring("wachtwoor d")
    ftp_remote_dire ctory = "" ' Leave blank if uploading to root directory
    ftp_files_to_pu t = chr(34)& request.QuerySt ring("bestandsN aam")&chr(34)
    LocalFolder = UploadPath & request.QuerySt ring("gebruiker snaam")


    On Error Resume Next
    Set oScript = wscript.CreateO bject("WSCRIPT. SHELL")
    Set oFileSys = Server.CreateOb ject("Scripting .FileSystemObje ct")
    Set objFSO = Server.CreateOb ject("Scripting .FileSystemObje ct")
    ' Build our ftp-commands file
    Set objTextFile =
    objFSO.CreateTe xtFile(Server.M apPath(request. QueryString("ge bruikersnaam")& "
    ..ftp"))
    objTextFile.Wri teLine "lcd " & LocalFolder
    objTextFile.Wri teLine "open " & ftp_address
    objTextFile.Wri teLine ftp_username
    objTextFile.Wri teLine ftp_password

    ' Check to see if we need to issue a 'cd' command
    If ftp_remote_dire ctory <> "" Then
    objTextFile.Wri teLine "cd " & ftp_remote_dire ctory
    End If

    objTextFile.Wri teLine "prompt"

    ' If the file(s) is/are binary (i.e. .jpg, .mdb, etc..), uncomment the
    following line' objTextFile.Wri teLine "binary"
    ' If there are multiple files to put, we need to use the command 'mput',
    instead of 'put'
    If Instr(1, ftp_files_to_pu t, "*",1) Then
    objTextFile.Wri teLine "mput " & ftp_files_to_pu t
    Else
    objTextFile.Wri teLine "put " & ftp_files_to_pu t
    End If
    objTextFile.Wri teLine "bye"
    objTextFile.Clo se
    Set objTextFile = Nothing
    ' Use cmd.exe to run ftp.exe, parsing our newly created command file
    strCMD = "ftp.exe -s:" &
    Server.MapPath( request.QuerySt ring("gebruiker snaam")&".ftp")
    NetSendCMD ="net.exe send 10.0.1.21 Gebruiker op werkstation "&
    request.ServerV ariables("REMOT E_ADDR") & " heeft een foutmelding ontvangen.
    Onder gebruikersaccou nt "&request.Query String("gebruik ersnaam")&". "
    strTempFile = "C:\" & oFileSys.GetTem pName( )
    ' 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.OpenTe xtFile (strTempFile, 1, False, 0)

    On Error Resume Next
    ' Grab output from temporary file
    strCommandResul t = "<html><hea d>" & vbcrlf
    strCommandResul t = StrCommandResul t & "<link
    rel="&chr(34)&" StyleSheet"&chr (34)&"
    href="&chr(34)& "../style.css"&chr( 34)&"type="&chr (34)&"text/css"&chr(34)&"m e
    dia="&chr(34)&" all"&chr(34)&"> " &vbcrlf
    strCommandResul t = StrCommandResul t & "</head><body>" & vbcrlf
    strCommandResul t = StrCommandResul t & oFile.ReadAll
    strCommandResul t = StrCommandResul t & "</body></html>" &vbcrlf
    oFile.Close
    ' Delete the temporary & ftp-command files
    'Call oFileSys.Delete File( strTempFile, True )
    'Call objFSO.DeleteFi le(
    Server.MapPath( request.QuerySt ring("gebruiker snaam")&".ftp") , True )
    Set oFileSys = Nothing
    Set objFSO = Nothing
    ' Print result of FTP session to screen
    StrSearch = split (strCommandResu lt,vbcrlf)
    'response.Write (StrTempFile.re adall)
    FOR i = 0 TO Ubound(strSearc h) -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="&succesM eldingKleur&">< center><strong> "&SuccesMelding &"</center></str
    ong></font><br>"
    END IF

    IF Trim(Melding(j) ) = "421" THEN
    StatusMelding = "<font
    color="&FoutMel dingKleur&"><ce nter><strong>"& FoutUploadMeldi ng&"</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="&FoutMel dingKleur&"><ce nter><strong>"& FoutLoginMeldin g&"</center></st
    rong></font><br>"
    NetSendCMD = NetSendCmd & "Gebruikern aam 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>Untitl ed 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;UR L=../FTPAccounts/admin_list_ftpa ccounts_form.as p?statusmeldin
    g=<%=(statusmel ding)%>&Gebruik ersnaam=<%=requ est.QueryString ("gebruikersnaa m
    ")%>">
    <%END IF%>
    <% IF session("user") = "1" THEN %>
    <meta http-equiv="refresh"
    content="100;UR L=../FTPAccounts/public_list_ftp accounts_form.a sp?statusmeldi
    ng=<%=(statusme lding)%>&Gebrui kersnaam=<%=req uest.QueryStrin g("gebruikersna a
    m")%>">
    <%END IF%>
    <% IF session("custom er") = "1" THEN %>
    <meta http-equiv="refresh"
    content="100;UR L=../FTPAccounts/customer_list_f tpaccounts_form .asp?statusmel
    ding=<%=(status melding)%>&Gebr uikersnaam=<%=r equest.QueryStr ing("gebruikers n
    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="#6699C C"><table width="649" height="387" border="0"
    align="center" cellpadding="0" cellspacing="0"
    background="../../Gfx/DKL.jpg" bgcolor="#66999 9">
    <tr>
    <td><table width="100%" border="0" cellspacing="0"
    cellpadding="0" >
    <tr>
    <td width="41%">&nb sp;</td>
    <td width="59%"><%= StatusMelding%> <%=strcmd%></td>
    </tr>
    </table></td>
    </tr>
    </table></td>
    </tr>
    </table>
    </body>
    </html>
    <%session("admi n") = "0"%>

    Thanks in advance


  • Ray Costanzo [MVP]

    #2
    Re: run dos command asp

    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


    "René" <blabla@spam.me .not.zonnet.nl> wrote in message
    news:41780a49$0 $48816$cd19a363 @news.wanadoo.n l...[color=blue]
    > 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..
    >[color=green]
    >>[/color]
    >[/color]
    [color=blue]
    > ' Use cmd.exe to run ftp.exe, parsing our newly created command file
    > strCMD = "ftp.exe -s:" &
    > Server.MapPath( request.QuerySt ring("gebruiker snaam")&".ftp")
    > NetSendCMD ="net.exe send 10.0.1.21 Gebruiker op werkstation "&
    > request.ServerV ariables("REMOT E_ADDR") & " heeft een foutmelding
    > ontvangen.
    > Onder gebruikersaccou nt "&request.Query String("gebruik ersnaam")&". "
    > strTempFile = "C:\" & oFileSys.GetTem pName( )
    > ' 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)[/color]


    Comment

    Working...