我现在利用wininet.dll进行FTP上传,想把某一个目录下的所有文件上传到FTP服务器上,如:c:\abc下已有1.doc,2.doc,3.doc共三个文件,而目标FTP服务器已经有1.doc,2.doc了,我现在如何判断c:\abc下的文件已存在于FTP服务器上(无所谓是否文件时间最新,我只做一次,不需要以后刷新),即我要能判断出1.doc,2.doc不需要上传,只要传3.doc就可以了在线等,急啊,请帮忙
我试图用FtpFindFirstFile来循环查找文件,可是总是第一个判断出存在了,第二个就判断不出来,难道是因为pData没有清空的缘故?怎么清空呢?

解决方案 »

  1.   

    我把代码贴一下,请大家帮忙看一下吧,谢谢拉~~    
        File1.Path = "c:\abc"
        Dim s
        s = ""
        File1.Refresh
        
        lnginet = InternetOpen("FTP Control", 1, vbNullString, vbNullString, 0)
        Dim pData As WIN32_FIND_DATA
        pData.cFileName = String(260, 0)
        
    'init the filename buffer
        If lnginet Then
       
          lnginetconn = InternetConnect(lnginet, "IP address", 0, "user", "password", 1, 0, 0)
          
          If lnginetconn Then
          
                For i = 0 To File1.ListCount - 1  '从本地目录中的第一个文件开始到FTP服务器上查找
                    blnRC = FtpFindFirstFile(lnginetconn, File1.List(i), pData & i, 0, 0)
                    If blnRC Then
                        Debug.Print "already have this file:  " & File1.List(i) 
                        strTemp = Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)
                        Debug.Print strTemp
                        pData.cFileName = String(260, 0)  '想在这里重新初始化,不过好象没有用                Else
                        blnrc2 = FtpPutFile(lnginetconn, File1.Path & "\" & File1.List(i), File1.List(i), 0, 0)   '如果没有这个文件,则同名上传                    If blnrc2 Then
                            Debug.Print "upload successful"   '上传成功
                        Else
                            Debug.Print "upload failed"       '上传失败
                        End If                End If
                    pData.cFileName = String(260, 0)
                Next i  '判断目录中的下一个文件
                
                    InternetCloseHandle lnginetconn
                    InternetCloseHandle lnginet
          Else
                Debug.Print Err.LastDllError
                Debug.Print "connect failed"
          End If
          
        Else
             MsgBox "ftp wrong"
        End If