Link to home
Start Free TrialLog in
Avatar of TimBare
TimBareFlag for United States of America

asked on

Need help creating an IIS FTP Virtual Directory progrommatically using VB .Net 2005

I've looked about everywhere that I can think of (here included) and I can't seem to find the answer for this question.

How do I create an FTP virtual directory in VB 2005

In my code, I'm using 'Username' as pretty well all of the variables (FTP VD name, and the root folder for the FV)

Here's the code i have that's not working:
    Private Sub sCreateVirtualDir(ByVal Username As String)

        Dim IISSchema As New System.DirectoryServices.DirectoryEntry("IIS://" & Username & "/Schema/AppIsolated")
        Dim CanCreate As Boolean = Not IISSchema.Properties("Syntax").Value.ToString.ToUpper() = "BOOLEAN"
        IISSchema.Dispose()

        If CanCreate Then
            Dim PathCreated As Boolean

            Try
                Dim IISAdmin As New System.DirectoryServices.DirectoryEntry("IIS://" & Username & "/MSFTPSVC/1/Root")

                'If the virtual directory already exists then delete it
                For Each VD As System.DirectoryServices.DirectoryEntry In IISAdmin.Children
                    If VD.Name = Username Then
                        IISAdmin.Invoke("Delete", New String() {VD.SchemaClassName, Username})
                        IISAdmin.CommitChanges()
                        Exit For
                    End If
                Next VD

                'Create and setup new virtual directory
                Dim VDir As System.DirectoryServices.DirectoryEntry = IISAdmin.Children.Add(Username, "Default FTP Site")
                VDir.Properties("Path").Item(0) = "F:\inetpub\ftpdocs\ftpcust\" & Username
                VDir.Properties("AppFriendlyName").Item(0) = Username
                VDir.Properties("AccessRead").Item(0) = True
                VDir.Properties("AccessWrite").Item(0) = True


                'the following are acceptable params
                'INPROC = 0
                'OUTPROC = 1
                'POOLED = 2
                VDir.Invoke("AppCreate", 1)
                VDir.CommitChanges()
            Catch Ex As Exception
                If PathCreated Then
                    System.IO.Directory.Delete("F:\inetpub\ftpdocs\ftpcust\" & Username)
                End If
                Throw Ex
            End Try
        End If
    End Sub

Open in new window


Any ideas would be GREATLY appreciated, as i've been working on this for about 3 1/2 hours this afternoon now...
Avatar of pramodsk40
pramodsk40
Flag of United States of America image

are you getting any error, first make sure you have permission for the f drive. Also try do it same drive where Inetput/wwwroot is present i.e c/d drive and see if it works...?
Avatar of TimBare

ASKER

I definitely have permission (if I run the iisftpdr script, I can create one just fine.)

I have to compile / run the exe on the server, which I don't have access to right now. I'll run it again and post the crash when I get home.

Inetpub is on the f drive.
Avatar of TimBare

ASKER

here's the screen shot of the crash, and the details

 User generated image
 
See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.Runtime.InteropServices.COMException (0x800706BA): The RPC server is unavailable.

   at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
   at System.DirectoryServices.DirectoryEntry.Bind()
   at System.DirectoryServices.DirectoryEntry.get_AdsObject()
   at System.DirectoryServices.PropertyValueCollection.PopulateList()
   at System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName)
   at System.DirectoryServices.PropertyCollection.get_Item(String propertyName)
   at CreateFTPUser.Form1.sCreateVirtualDir(String Username)
   at CreateFTPUser.Form1.Btn_CreateFTPUser_Click(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.ButtonBase.OnKeyUp(KeyEventArgs kevent)
   at System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m)
   at System.Windows.Forms.Control.ProcessKeyMessage(Message& m)
   at System.Windows.Forms.Control.WmKeyChar(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3615 (GDR.050727-3600)
    CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
CreateFTPUser
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Documents%20and%20Settings/Administrator/Desktop/CreateFTPUser.exe
----------------------------------------
Microsoft.VisualBasic
    Assembly Version: 8.0.0.0
    Win32 Version: 8.0.50727.3053 (netfxsp.050727-3000)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3614 (GDR.050727-3600)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Windows.Forms
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Runtime.Remoting
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
System.DirectoryServices
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.DirectoryServices/2.0.0.0__b03f5f7f11d50a3a/System.DirectoryServices.dll
----------------------------------------
System.Configuration
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3082 (QFE.050727-3000)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

Open in new window

Avatar of TimBare

ASKER

Any thoughts?

I've got just about everything else in the app working (checking if the username exists, creating AD user, creating the physical directory), I just can't peg this part of it...
ASKER CERTIFIED SOLUTION
Avatar of TimBare
TimBare
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TimBare

ASKER

After researching the issue, I found that this was the best solution, until someone comes up with a better one