Creating Virtual FTP Folder in ASP.NET

Discussion in 'ASP .Net Security' started by Joe, Jan 7, 2004.

  1. Joe

    Joe Guest

    I've been running into problems when trying to create a Virtual FTP folder
    in ASP.Net. I've tried it a few ways but none of them has worked so far. I
    have identity impersonation turned on, and the current user is an
    administrator on the machine, so I wouldn't think it's a permissions issue,
    but I can't think of anything else that it might be. The first way I tried,
    which worked fine in ASP but not ASP.Net, is:

    Dim Path
    Dim ftpSvc
    Dim vRoot
    Dim vDir
    Dim Site As Object
    Dim ftpSite As Object

    Path = "c:\inetpub\wwwroot\test\folder" ' assume this folder already
    exists on the server

    ftpSvc = GetObject("IIS://localhost/MsFtpSvc")
    On Error Resume Next

    For Each Site In ftpSvc
    Response.Write(ftpSvc.Class & "<br>")
    Response.Flush()
    If ftpSvc.Class = "IIsFtpService" Then
    ftpSite = Site
    Response.Write("setting vroot...")
    Response.Flush
    vRoot = ftpSite.GetObject("IIsFtpVirtualDir", "Root")
    If Err.Number = 0 Then
    Exit For
    Else
    Response.Write(Err.Description)
    Response.Flush()
    Err.Clear()
    End If
    End If
    Next
    ftpSvc = Nothing

    On Error GoTo 0
    If True Then
    vDir = vRoot.Create("IIsFtpVirtualDir", sUser)
    If Err.Number = 0 Then
    vDir.AccessRead = True
    vDir.Path = Path
    vDir.SetInfo()
    End If
    End If

    The above code worked fine in ASP, but when I tried to run it in ASP.NET, I
    got the following error:

    <<
    Cannot create ActiveX component.
    Description: An unhandled exception occurred during the execution of the
    current web request. Please review the stack trace for more information
    about the error and where it originated in the code.

    Exception Details: System.Exception: Cannot create ActiveX component.

    Source Error:
    Line 76: ftpSvc = GetObject("IIS://localhost/MsFtpSvc")
    >>


    I have also tried the following:

    Dim deRoot As New DirectoryEntry("IIS://localhost/MSFTPSVC/1/Root")
    Dim Path As String = "c:\inetpub\wwwroot\test\folder" ' assume this
    folder already exists on the server

    'Try
    deRoot.RefreshCache()
    Dim deNewVDir As DirectoryEntry = deRoot.Children.Add(sUser,
    "IIsFtpVirtualDir")

    deNewVDir.Properties("Path").Insert(0, Path)
    deNewVDir.CommitChanges()
    deRoot.CommitChanges()

    ' Create a Application
    ' Save Changes
    deNewVDir.CommitChanges()
    deRoot.CommitChanges()
    deNewVDir.Close()
    deRoot.Close()

    'Catch ex As Exception
    ' Response.Write(ex.Message)
    'End Try

    but this didn't work either. I got the following error:

    Object already exists
    Description: An unhandled exception occurred during the execution of the
    current web request. Please review the stack trace for more information
    about the error and where it originated in the code.

    Exception Details: System.Runtime.InteropServices.COMException: Object
    already exists

    Source Error:
    Line 47: deRoot.RefreshCache()

    It would seem the error is occuring in both examples around the same place -
    where it first tries to get the object for the MsFtpSvc.

    What do I need to change to make this work?
     
    Joe, Jan 7, 2004
    #1
    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. Joe
    Replies:
    0
    Views:
    2,564
  2. Jéjé
    Replies:
    2
    Views:
    407
    Jéjé
    Nov 30, 2005
  3. Replies:
    3
    Views:
    5,716
  4. ankita
    Replies:
    2
    Views:
    981
  5. D. Buck
    Replies:
    2
    Views:
    540
    D. Buck
    Jun 29, 2004
Loading...

Share This Page