Creating Virtual FTP Folder in ASP.NET

From: Joe (joe_at_innerspace.net)
Date: 01/07/04

  • Next message: Rob: "Mixing Form and Window Authentication"
    Date: Wed, 7 Jan 2004 09:38:02 -0600
    
    

    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?


  • Next message: Rob: "Mixing Form and Window Authentication"

    Relevant Pages

    • Re: Intermittant Server Error reading an MS Access DB
      ... Chuck ... > Dim i As Integer ... >> exception can be identified using the exception stack trace below. ...
      (microsoft.public.dotnet.framework.aspnet)
    • Re: Exporting to Access Help
      ... Eric the Rookie ... vRecordSet.Open "Review", vConnection, adOpenKeyset, ... Set Source = Documents.Open(FldrPath & RecordDoc) ... Dim vConnection As New ADODB.Connection ...
      (microsoft.public.word.vba.general)
    • Re: Extract form field data to Access
      ... Dim vConnection As New ADODB.Connection ... Dim RecordDoc As String ... I did this because I didn't understand the "DELETE * FROM Review" ... Dim oPath As String ...
      (microsoft.public.word.vba.general)
    • Re: Exporting to Access Help
      ... If you had two tables in the database - Review and Review1, ... Set Source = Documents.Open(FldrPath & RecordDoc) ... Dim vConnection As New ADODB.Connection ...
      (microsoft.public.word.vba.general)
    • Re: Find/Replace Text in Headers
      ... I didn't review your code. ... > Sub ReplaceHeadersFooters(sFind As String, ... Dim MySelection As Variant ...
      (microsoft.public.word.vba.general)

  • Quantcast