FTP目录列表问题 [英] FTP Directory listing problem

查看:82
本文介绍了FTP目录列表问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

Iam在列出SD卡中的目录文件时遇到了一些问题,如果SD卡中的文件超过3000个,IAM会遇到问题.文件为零.
请查看下面的代码片段,并让我知道如何获取确切的编号. &如果CARD超过3000个文件,则文件的详细信息:

Hello All,

Iam facing some problem in listing out the directory files in SD card, if the files in SD Card are more than 3000, iam getting the no. of files as ZERO.
Please see the below code snippet and let me know how can i get the exact no. & details of files if the CARD has more than 3000 files:

Private Function DoFilesList(sFilter As String) As Boolean
  On Error GoTo errHandler
  
  Dim dt As WIN32_FIND_DATA
  Dim hFile As Long, sFile
  Dim x As Long
  Dim sFilename As String

  Dim ftLastWriteTime As FILETIME
  Dim nFileSize As Long

  
  AddToLogFile ("Inside DoFileList")
  For x = cFileCardList.count To 1 Step -1
    cFileCardList.Remove x
  Next

  DoEvents
  hFile = FtpFindFirstFile(hConnect, sFilter, dt, INTERNET_FLAG_RELOAD, INTERNET_FLAG_NO_CACHE_WRITE)
  sFile = 1
  Do Until sFile = 0
    If ((dt.dwFileAttributes And Not vbDirectory)) Then
      sFilename = Left(dt.cFileName, InStr(1, dt.cFileName, String(1, 0), vbBinaryCompare) - ONE)
      '' 2.17.01 changes begin
      
      ftLastWriteTime = dt.ftLastWriteTime
      '' Size of the file needs to be calculated
      nFileSize = dt.nFileSizeHigh * (MAXDWORD + 1) + dt.nFileSizeLow
      AddtoCardList sFilename, nFileSize, FileTimeToDate(ftLastWriteTime)
      '' 2.17.01 changes end
    End If
    sFile = InternetFindNextFile(hFile, dt)
  Loop
  InternetCloseHandle (hFile)
  InternetCloseHandle (sFile)
  
  DoFilesList = True
  AddToLogFile ("Existing DoFilesList")
  Exit Function
errHandler:
  DoFilesList = False
  Resume Next
End Function

Private Sub AddtoCardList(ByVal sFilename As String, ByVal FileSize As Long, ByVal FileModifiedTime As Date)
   Dim newItem As cFileItem
   Set newItem = New cFileItem
   With newItem
      .Filename = sFilename
      .FileSize = FileSize 
      .LastWriteTime = FileModifiedTime 
   End With
   cFileCardList.Add newItem
   Set newItem = Nothing
End Sub



以下部分来自我们正在使用的FTP API:



the below part is from FTP APIs wich we are using:

Public Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Public Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (ByVal pub_lngInternetSession As Long, ByVal sServerName As String, ByVal nServerPort As Integer, ByVal sUsername As String, ByVal sPassword As String, ByVal lService As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
Public Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
Public Declare Function InternetFindNextFile Lib "wininet.dll" Alias "InternetFindNextFileA" (ByVal hFind As Long, lpvFindData As WIN32_FIND_DATA) As Long
Public Declare Function FtpDeleteFile Lib "wininet.dll" Alias "FtpDeleteFileA" (ByVal hFtpSession As Long, ByVal lpszFileName As String) As Long
Public Const INTERNET_OPTION_CONNECT_TIMEOUT = 2
Public Const INTERNET_OPTION_RECEIVE_TIMEOUT = 6
Public Const INTERNET_OPTION_SEND_TIMEOUT = 5



这是我们用来通过FTP套接字连接的功能:



This is the function which we are using to connect through FTP socket:

Private Function FtpConnect(ConnectionName As String, Port As Integer, User As String, Password As String, Optional ProxyName As String, Optional ProxyBypass As String) As Boolean
  On Error GoTo errHandler
  Dim thrh As String
  Dim k As Integer
  Dim pingchk As Boolean
  Dim URL As String
  Dim buffer As Long  ' number of milliseconds 
  Dim iRetVal As Integer 
  k = ZERO
  pingchk = TryPingToAll
  If pingchk = False Then
    AddToLogFile ("Pinging IP-address failed")
    FtpConnect = False
    Exit Function
  Else
    AddToLogFile ("Pinging IP-address success")
    
End If
  Do
  DoEvents
    If FTP_IP_SET = FTP_IP_USBDEVICE Then
        hSession = InternetOpen(ConnectionName, INTERNET_OPEN_TYPE_DIRECT, ProxyName, ProxyBypass, INTERNET_FLAG_NO_CACHE_WRITE)
        URL = FTP_IP_USBDEVICE
        thrh = "USB Device"
        CallbackResult = InternetSetStatusCallback(hSession, AddressOf InternetStatusCallback)
        hConnect = InternetConnect(hSession, FTP_IP_USBDEVICE, Port, User, Password, INTERNET_SERVICE_FTP, FTP_TRANSFER_TYPE_BINARY, DW_CONTEXT&)
    End If

    If FTP_IP_SET = FTP_IP_ETH0 Then
        hSession = InternetOpen(ConnectionName, INTERNET_OPEN_TYPE_DIRECT, ProxyName, ProxyBypass, INTERNET_FLAG_NO_CACHE_WRITE)
        URL = FTP_IP_ETH0
        thrh = "Ethernet"
        CallbackResult = InternetSetStatusCallback(hSession, AddressOf InternetStatusCallback)
        hConnect = InternetConnect(hSession, FTP_IP_ETH0, Port, User, Password, INTERNET_SERVICE_FTP, FTP_TRANSFER_TYPE_BINARY, DW_CONTEXT&)
    End If
    If FTP_IP_SET = FTP_IP_WIFI Then
        hSession = InternetOpen(ConnectionName, INTERNET_OPEN_TYPE_DIRECT, ProxyName, ProxyBypass, INTERNET_FLAG_NO_CACHE_WRITE)
        URL = FTP_IP_WIFI
        thrh = "WifI Device"
        CallbackResult = InternetSetStatusCallback(hSession, AddressOf InternetStatusCallback)
        hConnect = InternetConnect(hSession, FTP_IP_WIFI, Port, User, Password, INTERNET_SERVICE_FTP, FTP_TRANSFER_TYPE_BINARY, DW_CONTEXT&)
    End If
    If FTP_IP_SET = FTP_IP_WIFI_AP Then
        hSession = InternetOpen(ConnectionName, INTERNET_OPEN_TYPE_DIRECT, ProxyName, ProxyBypass, INTERNET_FLAG_NO_CACHE_WRITE)
        URL = FTP_IP_WIFI_AP
        thrh = "WifI Device"
        CallbackResult = InternetSetStatusCallback(hSession, AddressOf InternetStatusCallback)
        hConnect = InternetConnect(hSession, FTP_IP_WIFI_AP, Port, User, Password, INTERNET_SERVICE_FTP, FTP_TRANSFER_TYPE_BINARY, DW_CONTEXT&)
    End If
    'Increased FTP Timeouts 
    buffer = 120000 ' 2 minutes
    iRetVal = InternetSetOption(hConnect, INTERNET_OPTION_RECEIVE_TIMEOUT, buffer, 4)
    buffer = 120000 ' 2 minutes
    iRetVal = InternetSetOption(hConnect, INTERNET_OPTION_SEND_TIMEOUT, buffer, 4)
    buffer = 120000 ' 2 minutes
    iRetVal = InternetSetOption(hConnect, INTERNET_OPTION_CONNECT_TIMEOUT, buffer, 4)

    
    If hSession <> ZERO And hConnect <> ZERO Then
       Exit Do
    End If
    InternetCloseHandle (hSession)
    InternetCloseHandle (hConnect)
    hSession = ZERO: hConnect = ZERO
    k = k + ONE
  Loop Until (hSession <> ZERO And hConnect <> ZERO) Or k = ONE
  If hSession <> ZERO And hConnect <> ZERO Then
    DoEvents
    FtpConnect = True
    Exit Function
  Else
     FtpConnect = False
  End If
  Exit Function
errHandler:
  InternetCloseHandle (hSession)
  InternetCloseHandle (hConnect)
  FtpConnect = False
End Function


如果文件大小超过3GB,请建议如何列出目录

谢谢.
Dinesh


Please suggest how can i list out directory if file siize is more than 3GB

Thanks.
Dinesh

推荐答案

为什么要尝试通过SD卡通过FTP传输文件?

为什么不在Visual Basic中使用目录调用来解析目录树,然后在Visual Basic中使用文件副本来复制SD卡中所需的全部或全部文件呢?
Why are you trying to FTP the files from an SD Card?

Why not use directory calls in Visual Basic to parse the directory tree then use file copies in Visual Basic to copy all or only the files you want from the SD Card?


这篇关于FTP目录列表问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆