ASP and FTP

Discussion in 'ASP General' started by Vanessa, Aug 4, 2008.

  1. Vanessa

    Vanessa Guest

    Hi Everyone,

    I have a new project for which we want to exchange files with our remote
    support center via FTP without human intervention.

    Our company is using Microsoft Navision while our remote support center is
    using their own system (for which I don’t know what it is).

    My original idea is having an ASP programming script, which will be
    scheduled to run daily on the server, to perform following:

    1) Check Navision to see if any new orders are created for that particular
    location on that day. If yes, the script will generate the CSV file and
    upload the file into FTP automatically.

    2) It will also check if any new files are uploaded by our support center on
    that day. If yes, it will download the file from the FTP and ‘import’ data
    back to Navision.

    However, I’ve tested out the FTP function with ASP programming, but it gave
    me access denied permission as the ‘website account’ doesn’t have enough
    access level to execute the FTP command lines.

    I have researched online and experts suggested that we will need to
    configure IIS to use an impersonation account with admin rights on our site
    but that might give the security risks involved. I don’t think we want to
    set the ‘website account’ with Admin rights.

    Please advise if any other ways I can have this problem resolved, or any
    other solutions can be achieved the same goal will be greatly appreciated.

    THANK YOU!!

    Here is the coding:

    <%
    Dim strHost, strUser, strPass, strMode, LocalDir, RemoteDir
    Dim Output, ReturnCode, strScript
    Const COMMAND_FTP = "ftp.exe -i -s:"

    strHost = "ftp://###.###.###.###/"
    strUser = "username"
    strPass = "password"
    strMode = "ascii" '=== "ascii" / "binary"
    LocalDir = "\FTPTEST"
    RemoteDir = "/images/"

    Function FTP( strCMD )
    Dim objFSO, strFile, objTempFldr, objFile, objRegExp
    Dim objShell, WSX, ReturnCode, Output, strLog, strErrorLog

    Set objFSO = CreateObject("Scripting.FileSystemObject")

    strFile = Server.MapPath("FTPTEST/temptemp.ftp")
    response.write strFile & "<BR>"

    if not objFSO.FileExists( strFile ) then objFSO.CreateTextFile( strFile )
    Set objFile = objFSO.OpenTextFile( strFile, 2, True )

    objFile.WriteLine( strUser )
    objFile.WriteLine( strPass )
    If LocalDir <> "" Then objFile.WriteLine( "lcd " & LocalDir )
    If RemoteDir <> "" Then objFile.WriteLine( "cd " & RemoteDir )
    objFile.WriteLine( strMode )

    objFile.WriteLine( strCMD )
    objFile.WriteLine( "bye" )
    objFile.Close()

    Set objShell = Server.CreateObject("WScript.Shell")

    set WSX = objShell.Exec( COMMAND_FTP & strFile & " " & strHost ) '<-- ERROR
    ERROR!!! WshShell.Exec error '80070005' Access is denied.
    set ReturnCode = WSX.StdErr
    set Output = WSX.stdOut
    strErrorLog = Server.MapPath("FTPTEST") & "ftpErrors.txt"
    strLog = Server.MapPath("FTPTEST") & "ftpLog.txt"

    Set objFile = objFSO.OpenTextFile( strErrorLog, 2, True )
    objFile.Write( ReturnCode.ReadAll() )
    objFile.Close()

    Set objFile = objFSO.OpenTextFile( strLog, 2, True )
    objFile.Write( Output.ReadAll() )
    objFile.Close()
    set objFSO = nothing
    set objFile = nothing

    objFSO.DeleteFile strFile, True
    set objFSO = nothing

    Set objRegExp = New RegExp
    objRegExp.IgnoreCase = True

    objRegExp.Pattern = "not connected|invalid command|error"

    If (objRegExp.Test( Output.ReadAll ) = True ) or (objRegExp.Test(
    ReturnCode.ReadAll ) ) Then 'on one line
    FTP = False
    Else
    FTP = True
    End If
    Set objRegExp = nothing
    End Function

    strCommands = "GET ac.gif"

    'calling the function =============================================
    SUCCESSTEST = FTP( strCommands )
    response.Write SUCCESSTEST
    %>
    Vanessa, Aug 4, 2008
    #1
    1. Advertising

  2. This is not a job to do via ASP. Why do you think ASP needs to be
    involved in this? This process you have described does not involve
    generating html to be served to a client.

    This is a task that needs to be scheduled on your server's operating
    system. See:
    http://www.aspfaq.com/show.asp?id=2143


    Vanessa wrote:
    > Hi Everyone,
    >
    > I have a new project for which we want to exchange files with our
    > remote support center via FTP without human intervention.
    >
    > Our company is using Microsoft Navision while our remote support
    > center is using their own system (for which I don't know what it is).
    >
    > My original idea is having an ASP programming script, which will be
    > scheduled to run daily on the server, to perform following:
    >
    > 1) Check Navision to see if any new orders are created for that
    > particular location on that day. If yes, the script will generate
    > the CSV file and upload the file into FTP automatically.
    >
    > 2) It will also check if any new files are uploaded by our support
    > center on that day. If yes, it will download the file from the FTP
    > and 'import' data back to Navision.
    >
    > However, I've tested out the FTP function with ASP programming, but
    > it gave me access denied permission as the 'website account' doesn't
    > have enough access level to execute the FTP command lines.
    >
    > I have researched online and experts suggested that we will need to
    > configure IIS to use an impersonation account with admin rights on
    > our site but that might give the security risks involved. I don't
    > think we want to set the 'website account' with Admin rights.
    >
    > Please advise if any other ways I can have this problem resolved, or
    > any other solutions can be achieved the same goal will be greatly
    > appreciated.
    >
    > THANK YOU!!
    >
    > Here is the coding:
    >
    > <%
    > Dim strHost, strUser, strPass, strMode, LocalDir, RemoteDir
    > Dim Output, ReturnCode, strScript
    > Const COMMAND_FTP = "ftp.exe -i -s:"
    >
    > strHost = "ftp://###.###.###.###/"
    > strUser = "username"
    > strPass = "password"
    > strMode = "ascii" '=== "ascii" / "binary"
    > LocalDir = "\FTPTEST"
    > RemoteDir = "/images/"
    >
    > Function FTP( strCMD )
    > Dim objFSO, strFile, objTempFldr, objFile, objRegExp
    > Dim objShell, WSX, ReturnCode, Output, strLog, strErrorLog
    >
    > Set objFSO = CreateObject("Scripting.FileSystemObject")
    >
    > strFile = Server.MapPath("FTPTEST/temptemp.ftp")
    > response.write strFile & "<BR>"
    >
    > if not objFSO.FileExists( strFile ) then objFSO.CreateTextFile(
    > strFile ) Set objFile = objFSO.OpenTextFile( strFile, 2, True )
    >
    > objFile.WriteLine( strUser )
    > objFile.WriteLine( strPass )
    > If LocalDir <> "" Then objFile.WriteLine( "lcd " & LocalDir )
    > If RemoteDir <> "" Then objFile.WriteLine( "cd " & RemoteDir )
    > objFile.WriteLine( strMode )
    >
    > objFile.WriteLine( strCMD )
    > objFile.WriteLine( "bye" )
    > objFile.Close()
    >
    > Set objShell = Server.CreateObject("WScript.Shell")
    >
    > set WSX = objShell.Exec( COMMAND_FTP & strFile & " " & strHost ) '<--
    > ERROR ERROR!!! WshShell.Exec error '80070005' Access is denied.
    > set ReturnCode = WSX.StdErr
    > set Output = WSX.stdOut
    > strErrorLog = Server.MapPath("FTPTEST") & "ftpErrors.txt"
    > strLog = Server.MapPath("FTPTEST") & "ftpLog.txt"
    >
    > Set objFile = objFSO.OpenTextFile( strErrorLog, 2, True )
    > objFile.Write( ReturnCode.ReadAll() )
    > objFile.Close()
    >
    > Set objFile = objFSO.OpenTextFile( strLog, 2, True )
    > objFile.Write( Output.ReadAll() )
    > objFile.Close()
    > set objFSO = nothing
    > set objFile = nothing
    >
    > objFSO.DeleteFile strFile, True
    > set objFSO = nothing
    >
    > Set objRegExp = New RegExp
    > objRegExp.IgnoreCase = True
    >
    > objRegExp.Pattern = "not connected|invalid command|error"
    >
    > If (objRegExp.Test( Output.ReadAll ) = True ) or (objRegExp.Test(
    > ReturnCode.ReadAll ) ) Then 'on one line
    > FTP = False
    > Else
    > FTP = True
    > End If
    > Set objRegExp = nothing
    > End Function
    >
    > strCommands = "GET ac.gif"
    >
    > 'calling the function =============================================
    > SUCCESSTEST = FTP( strCommands )
    > response.Write SUCCESSTEST
    > %>


    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
    Bob Barrows [MVP], Aug 4, 2008
    #2
    1. Advertising

  3. Vanessa

    stevewa Guest

    Vanessa, ahve you had any success resolving this?
    stevewa, Aug 13, 2008
    #3
  4. Gazing into my crystal ball I observed =?Utf-8?B?c3RldmV3YQ==?=
    <> writing in news:25BBE46A-4A81-4C88-
    :

    > Vanessa, ahve you had any success resolving this?


    You might want to look at [http://benmeg.com/code/asp/ftp.asp.html], FTP
    without a component. I use it all the time, works great.

    --
    Adrienne Boswell at Home
    Arbpen Web Site Design Services
    http://www.cavalcade-of-coding.info
    Please respond to the group so others can share
    Adrienne Boswell, Aug 13, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nico Grubert
    Replies:
    0
    Views:
    617
    Nico Grubert
    Nov 24, 2005
  2. Nico Grubert
    Replies:
    0
    Views:
    433
    Nico Grubert
    Nov 25, 2005
  3. Ari Brown

    Net::FTP and ftp.dir()

    Ari Brown, Jul 16, 2007, in forum: Ruby
    Replies:
    0
    Views:
    76
    Ari Brown
    Jul 16, 2007
  4. D. Buck
    Replies:
    2
    Views:
    458
    D. Buck
    Jun 29, 2004
  5. Asaf Sinai
    Replies:
    1
    Views:
    231
    Chris Davies
    Jul 4, 2006
Loading...

Share This Page