VB程序按日期生成文件夹,日期文件夹里再生成50-70个文件夹,代表50-70个商户,每个文件夹里有不同的文件,然后用For Each对日期文件夹进行遍历,用FTP上传到WEB系统,但有时会少一到两个文件夹,有时不少,这个不确定,是什么原因导致没有上传,是For Each没有遍历出来吗?以下是代码:    strHostIP = "192.168.0.0"  '   
    strUser = "web"
    strPwd = "web"
    
    strSettleDate = Mid(gStrSettleDate, 1, 4) & Mid(gStrSettleDate, 6, 2) & Right(gStrSettleDate, 2)  '日期文件夹
    strRptPath = gSettReportPath & strSettleDate  '路径
    If fs.FolderExists(strRptPath) = False Then
        strMessage = "无法上传报表到web管理系统指定目录!找不到存放报表的路径!请先确认日期是否正确,报表清算日期为" & gStrSettleDate
        MsgBox strMessage, vbOKOnly, "Command_create_table_Click"
        Exit Function
    End If    Set oFiles = fs.GetFolder(strRptPath).SubFolders  '日期文件夹下的子文件夹
    
    For Each ofolder In oFiles        If ofolder.name <> "" Then
            ftpFile strHostIP, strUser, strPwd, strRptPath & "\" & ofolder.name, "/" & strSettleDate & "/" & ofolder.name, False
            For i = 0 To 300
                Delay1s
            Next
        End If
    Next
    
    ftpReport = True

解决方案 »

  1.   

    没有看到对 ftpFile 传输状态的判断,你怎么保证肯定传输成功了?
      

  2.   

    这个是传输
    Dim fsoname As New FileSystemObject
        Dim CommandStr As String
        Dim strRemoteFolder() As String
        Dim i As Integer
        
        Open App.path + "\PutFile.bat" For Output Access Write As #1
        Print #1, "open " & strHostIP
        Print #1, "user " & strUser & " " & strPwd
    '    Print #1, "binary on"
        Print #1, "prompt off"
        Print #1, "lcd " & strLocalPath
            
        strRemoteFolder = Split(strRemotePath, "/")
        
        For i = 1 To UBound(strRemoteFolder)
            Print #1, "mkdir " & "/" & strRemoteFolder(i - 1) & "/" & strRemoteFolder(i)
        Next
        
        If bln_p_or_g Then
            Print #1, "get " & strRemotePath & "/" & "*"
        Else
            Print #1, "cd  " & strRemotePath
            Print #1, "mput " & "*"
        End If
        Print #1, "by"
        Print #1,
        Print #1,    Close #1
        CommandStr = "ftp -n -s:" & App.path & "\PutFile.bat"    Shell CommandStr, 2    ftpFile = True
      

  3.   

    你怎么保证 ftp 命令行一定成功?
      

  4.   

    问题找到了For i = 0 To 300
       Delay1s
    Next、Public Sub Delay1s()
    '延迟1秒
        Dim i As Integer
        For i = 0 To 1000
            DoEvents
        Next i
    End Sub
    把300改为400就可以了,因为有的文件夹内的文件比较多,比较大,上传的时间长
      

  5.   

    所以说你的程序只是“假定ftp成功”,而不是“保证ftp成功”。