- 帖子
- 33
- 主題
- 10
- 精華
- 0
- 積分
- 74
- 點名
- 0
- 作業系統
- win7
- 軟體版本
- 2007
- 閱讀權限
- 20
- 性別
- 男
- 註冊時間
- 2011-6-9
- 最後登錄
- 2024-7-8
|
回復 6# Joforn - Private Function FTPFolder(ByVal Url As String, _
- Optional ByVal UserName As String, _
- Optional ByVal PassWord As String, _
- Optional ByVal Port As Integer) As Object
- Dim objShell As Object
-
- If Len(Url) Then
- If Len(UserName) Then Url = UserName & ":" & PassWord & "@" & Url
- If Port > 0 Then Url = Url & ":" & Port
- Set objShell = CreateObject("Shell.Application")
- Set FTPFolder = objShell.Namespace("FTP://" & Url)
- End If
- End Function
- Sub test()
- Dim objFolder As Object
- Dim objItem As Object
- Dim selectFolder
-
- Set objFolder = FTPFolder("118.163.50.55/firmware_software_version_files/", "xxxxx", "xxxx")
-
- If Not (objFolder Is Nothing) Then
-
- selectFolder = objFolder
-
- Call 列出檔案清單(selectFolder)
- End If
- End Sub
- Sub 列出檔案清單(ByVal theDir As String)
- Dim pt As Range
-
- Set pt = Sheet1.Range("a2")
- Call 設定標題(1)
-
- If Len(Dir(theDir, vbDirectory)) > 0 Then
- If (GetAttr(theDir) And vbDirectory) = vbDirectory Then
- Call FileIOUtility.RetrivalFileList(theDir, pt, 0)
- End If
- End If
-
- pt.Worksheet.Columns("A:B").AutoFit
- End Su
- Function RetrivalFileList(ByVal strDir As String, ByRef myRange As Range, ByRef depth As Integer)
- Dim thePath As String
- Dim strSdir As String
- Dim theDirs As Scripting.Folders
- Dim theDir As Scripting.Folder
- Dim theFile As Scripting.File
- Dim myFso As Scripting.FileSystemObject
- Dim subFolderCount As Integer
-
- Set myFso = New Scripting.FileSystemObject
- If Right(strDir, 1) <> "" Then strDir = strDir & ""
- thePath = thePath & strDir
-
- '列出第一層根目錄的檔案
- If depth = 0 Then
- For Each theFile In myFso.GetFolder(strDir).Files
- myRange = theFile.Path
- myRange.Next = theFile.Size
- myRange.Next.Next = theFile.DateLastModified
- Set myRange = myRange.Offset(1, 0)
- Next
- depth = 1
- End If
-
- '尋找所有子目錄的檔案
- Set theDirs = myFso.GetFolder(strDir).SubFolders
- For Each theDir In theDirs
- For Each theFile In theDir.Files
- myRange = theFile.Path
- myRange.Next = theFile.Size
- myRange.Next.Next = theFile.DateLastModified
- Set myRange = myRange.Offset(1, 0)
- Next
- RetrivalFileList strDir:=theDir.Path, myRange:=myRange, depth:=depth
- Next
- Set myFso = Nothing
- End Function
-
複製代碼 我將檔案路徑丟給selectFolder,會出問題
但如果我給selectFolder 的路徑是電腦本機的卻可以執行,
給selectFolder 完整的FTP路徑也會出錯,
是因為FTP查詢的方式跟本機的不一樣嗎?? |
|