Creating Virtual FTP Folder in ASP.NET

J

Joe

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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top