home *** CD-ROM | disk | FTP | other *** search
- <%@ LANGUAGE="VBSCRIPT" %>
-
- <%
- '--------------------------------------------------------------
- ' Xceed FTP Library - FTP Client sample application
- ' Copyright (c) 2000 Xceed Software Inc.
- '
- ' [FtpClient.asp]
- '
- ' This simple ASP sample demonstrates how to retrieve a listing of the items
- ' in a specifed remote folder by using the GetFolderContents method.
- '
- ' Please see documentation for details on how it works.
- '
- ' This file is part of the Xceed FTP Library sample applications
- ' The source code in this file is only intended as a supplement
- ' to Xceed FTP Library's documentation, and is provided "as is",
- ' without warranty of any kind, either expressed or implied.
- '--------------------------------------------------------------
-
- Dim xFtp
- Dim sServerAddress
- Dim sPort
- Dim sUsername
- Dim sPassword
- Dim sFolder
-
- ' Create a new instance of the XceedFtp object
- Set xFtp = CreateObject( "XceedSoftware.XceedFtp" ) ' reate our Xceed Ftp object
-
- ' If you are using the free trial version of Xceed FTP Library, you'll
- ' need to run the Xceed FTP trial version's setup program on
- ' the system where your IIS server is located, otherwise the library
- ' will complain it is not licensed.
-
- ' If you are a registered user, uncomment the following line
- ' and replace the text in quotes with your license key.
-
- ' Call xFtp.License("your license key goes here")
-
- sServerAddress = trim( Request( "ServerAddress" ) )
- sPort = trim( Request( "Port" ) )
- sUsername = trim( Request( "Username" ) )
- sPassword = trim( Request( "Password" ) )
- sFolder = trim( Request( "Folder" ) ) ' The sFolder variable is only set when this ASP page
- ' calls itself when a folder is selected.
-
- xFtp.ServerAddress = sServerAddress ' Set the ServerAddresss property
- xFtp.ServerPort = sPort ' Set the ServerPort property (default = 21)
- xFtp.Username = sUsername ' Set the Username property (default = anonymous)
- xFtp.Password = sPassword ' Set the Password property (default = guest)
-
- On Error Resume Next
-
- Call xFtp.Connect() 'Connect to the FTP server
-
- If Err.Number = 0 Then
- Response.Write( "<B>Connected to " & sServerAddress & "<BR><BR></B>" )
-
- ' List the ObtainFolderListing procedure.
- Call ObtainFolderListing( sFolder )
-
- If Err.Number <> 0 Then
- Response.Write( Err.Description & " #" & Err.Number & "<BR><BR>" )
- End IF
- Else
- Response.Write( Err.Description & " #" & Err.Number & "<BR><BR>" )
- End If
-
- Set xFtp = Nothing ' Release our instance of the XceedFtp object
- Set xFolderItems = Nothing
-
- ' --------------------------------------------------------------
- ' Once we are connected, we will retrieve the folder contents
- ' of the selected folder. The current working folder is not
- ' relevant if we simply call the GetFolderContents method
- ' and pass it the complete path and name of the folder we want
- ' to list the contents of.
- ' --------------------------------------------------------------
- Public Sub ObtainFolderListing( sName )
-
- Dim xFolderItems
- Dim xItem
- Dim sNewFolder
-
- On Error Resume Next
-
- ' Get a listing of the folder contents and place it in our XceedFtpFolderItems collection
- Set xFolderItems = xFtp.GetFolderContents( sName, 0 )
- Call RetrieveParentFolder( sFolder )
-
- If Err.Number = 0 Then
- Response.Write( "<TABLE WIDTH=""600"" BORDER=""2"" CELLSPACING=""0"" CELLPADDING=""0"">" & _
- "<TR BGCOLOR=""BLUE"">" & _
- "<TD ALIGN=""CENTER""><B><FONT COLOR=""WHITE"">Date</FONT></B></TD>" & _
- "<TD ALIGN=""CENTER""><B><FONT COLOR=""WHITE"">Size (in bytes)</FONT></B></TD>" & _
- "<TD ALIGN=""CENTER""><B><FONT COLOR=""WHITE"">Type</FONT></B></TD>" & _
- "<TD ALIGN=""CENTER""><B><FONT COLOR=""WHITE"">Name</FONT></B></TD>" & _
- "</TR>" )
-
- ' Loop through each item in the XceedFtpFolderItems collection and retrieve the
- ' information on each item.
- For Each xItem In xFolderItems
-
- Select Case xItem.ItemType
- Case 0 'Is a file
- Response.Write( "<TR>" & _
- "<TD WIDTH=""200"">" & xItem.Date & "</TD>" & _
- "<TD WIDTH=""100"">" & xItem.FileSize & "</TD>" & _
- "<TD WIDTH=""100"">File</TD>" & _
- "<TD WIDTH=""200""><A HREF=""Ftp://" & sUsername & ":" & sPassword & "@" & sServerAddress & ":" & sPort & "/" & sFolder & "/" & xItem.ItemName & """>" & xItem.ItemName & "</A></TD>" & _
- "</TR>" )
-
- Case 1 'Is a folder
- sNewFolder = sFolder
-
- If ( Len( sNewFolder ) > 0 ) Then
- sNewFolder = sNewFolder & "/"
- End If
-
- sNewFolder = sNewFolder & xItem.ItemName 'Set the new path and folder
-
- ' The link that will be written actualy recalls the XceedFtp.asp page and
- ' gets the folder contents of the new folder specified.
- Response.Write( "<TR>" & _
- "<TD WIDTH=""200"">" & xItem.Date & "</TD>" & _
- "<TD WIDTH=""100"">" & xItem.FileSize & "</TD>" & _
- "<TD WIDTH=""100"">Directory</TD>" & _
- "<TD WIDTH=""200""><A HREF=""XceedFtp.asp?ServerAddress=" & sServerAddress & "&Port=" & sPort & "&Username=" & sUsername & "&Password=" & sPassword & "&Folder=" & sNewFolder & """ > " & xItem.ItemName & "</A></TD>" & _
- "</TR>" )
-
- Case 2 'Is a link
- If LinkType( xItem.ItemName ) = "folder" then
-
- sNewFolder = sFolder
-
- If ( Len( sNewFolder ) > 0 ) Then
- sNewFolder = sNewFolder & "/"
- End If
-
- sNewFolder = sNewFolder & xItem.ItemName ' Set the new path and folder
-
- Response.Write( "<TR>" & _
- "<TD WIDTH=""200"">" & xItem.Date & "</TD>" & _
- "<TD WIDTH=""100"">" & xItem.FileSize & "</TD>" & _
- "<TD WIDTH=""100"">Directory Link</TD>" & _
- "<TD WIDTH=""200""><A HREF=""XceedFtp.asp?ServerAddress=" & sServerAddress & "&Port=" & sPort & "&Username=" & sUsername & "&Password=" & sPassword & "&Folder=" & sNewFolder & """ > " & xItem.ItemName & "</A></TD>" & _
- "</TR>" )
- Else
- If LinkType( xItem.ItemName ) = "file" Then
- Response.Write( "<TR>" & _
- "<TD WIDTH=""200"">" & xItem.Date & "</TD>" & _
- "<TD WIDTH=""100"">" & xItem.FileSize & "</TD>" & _
- "<TD WIDTH=""100"">File Link</TD>" & _
- "<TD WIDTH=""200""><A HREF=""Ftp://" & sUsername & ":" & sPassword & "@" & sServerAddress & ":" & sPort & "/" & sFolder & "/" & xItem.ItemName & """>" & xItem.ItemName & "</A></TD>" & _
- "</TR>" )
- End If
- End If
-
- End Select
- Next
- Response.Write( "</TABLE>" )
- Else
- Response.Write( "Unable to list the files in " & sFilename & "<BR>" )
- Response.Write( Err.Description & " #" & Err.Number & "<BR><BR>" )
- End If
-
- End Sub
-
- ' --------------------------------------------------------------
- ' The RetrieveParentFolder procedure is used to get the parent
- ' folder of the current remote folder. Since we are initially
- ' in the root folder at all times, we must change the current
- ' folder to the same folder being used by the GetFolderContents
- ' method before being able to retreive it's parent folder.
- ' --------------------------------------------------------------
- Public Sub RetrieveParentFolder( sName )
-
- Dim sParentFolder
- Dim nPos
-
- If Len( sName ) > 0 Then
- Call xFtp.ChangeCurrentFolder( sName ) ' Change the current remote folder
- End If
-
- sName = xFtp.CurrentFolder ' Get the current folder
- nPos = InStrRev( sName, "\" )
- sParentFolder = Mid( sName, 1, nPos ) ' Parse our folder to retrieve it's parent
-
- Response.Write( "<TABLE WIDTH=""600"" BORDER=""0"" CELLSPACING=""0"" CELLPADDING=""0"">" & _
- "<TR>" & _
- "<TD WIDTH=""500"" ALIGN=""LEFT""><B>You are currently located in " & sFolder & "</B></TD>" & _
- "<TD WIDTH=""100"" ALIGN=""RIGHT""><A HREF=""XceedFtp.asp?ServerAddress=" & sServerAddress & "&Port=" & sPort & "&Username=" & sUsername & "&Password=" & sPassword & "&Folder=" & sParentFolder & """ >Parent Folder</A></TD>" & _
- "</TR>" & _
- "</TABLE>" )
-
- End Sub
-
- ' --------------------------------------------------------------
- ' Some FTP servers use links instead of files or folders. However
- ' these links link to a file or folder than can be access in the
- ' same way as a regular file or folder. Since we do not know to
- ' what the link links, we will do a "test" with the
- ' ChangeCurrentFolder method of the Xceed Ftp Library. If the
- ' link links to a file, an error will be returned and we will
- ' return "file". If there is no error and we were able to
- ' successfully change folders, then we will return "folder".
- ' --------------------------------------------------------------
- Public Function LinkType( sName )
-
- On Error Resume Next
-
- Call xFtp.ChangeCurrentFolder( sName )
-
- If Err.Number = 0 then
- LinkType = "folder"
- Else
- LinkType = "file"
- Err = 0
- End If
-
- End Function
-
- ' --------------------------------------------------------------
-
-
- %>
-
-
-
-
-