467,166 Members | 1,069 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,166 developers. It's quick & easy.

Creating Virtual FTP Folder in ASP.NET

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?

Jul 21 '05 #1
  • viewed: 1151
Share:

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by news.iq.ca | last post: by
7 posts views Thread by Jaydeep | last post: by
1 post views Thread by Eric Voigt | last post: by
15 posts views Thread by David Thielen | last post: by
3 posts views Thread by tshad | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.