在局域网里需要多台计算机将文件传输给一台server,有可能文件会很大,应该使用何种方式。
详细,最好有代码!

解决方案 »

  1.   

    用winsock控件,基于TCP/IP进行文件传送Private Sub cmdSend_Click()
        '向服务器发送文件
        Dim myFile() As Byte
        Dim lngFile As Long    '文件长度
        Dim FileName As String '文件名称
        Static i As Single
        
        sockClient.Close
        sockClient.Connect
        
        Do
            DoEvents
            If sockClient.State = sckConnected Then
                Exit Do
            Else
                i = i + 1
                If i > 200000 Then
                    Dim box As String
                    box = MsgBox("是否放弃?", vbYesNo, "连接失败:")
                    If box = vbYes Then
                        i = 0
                        Exit Do
                    Else
                        i = 0
                    End If
                End If
            End If
            DoEvents
        Loop
        lenth = 0
        '检查是否与服务器连接
        If sockClient.State = sckConnected Then        FileName = VB.App.Path & "\1.jpg"  '取得文件名及路径
            lngFile = FileLen(FileName)        '取得文件长度
            ReDim myFile(lngFile - 1) As Byte  '初始化数组
            
            Open FileName For Binary As #1     '打开文件
            Get #1, , myFile                   '将文件写入数组
            Close #1                           '关闭文件        sockClient.SendData myFile           '发送    Else
            MsgBox "没有连接"
        End If
    End Sub
    Private Sub sockServer_DataArrival(Index As Integer, ByVal bytesTotal As Long)
        '接收文件
        Static i As Long
        Dim myFile() As Byte
        Dim myLong As Double
        Dim myPath As String
        myPath = VB.App.Path & "\a.doc"
        cmdC.Caption = "正在接收数据... " & bytesTotal
        ReDim myFile(0 To bytesTotal - 1) '此处也可以是(0 To bytesTotal-1)
        
        sockServer(Index).GetData myFile
        i = i + 1
      
        Open myPath For Binary As #1 '新建文件
        Put #1, lenth + 1, myFile                    '将收到的数据写入新文件中
        Close #1                                     '关闭
        '记录文件长度
        lenth = lenth + UBound(myFile) - LBound(myFile) + 1
        
    End Sub
      

  2.   

    myPath = VB.App.Path & "\a.doc"
    这一句改成:
    myPath = VB.App.Path & "\a.jpg"
    要示然文件格式不对
      

  3.   

    copy c:\data.dat \\server\shared\data.dat
      

  4.   

    好像socket传输文件大小不能超过8k,不然的话后面的8k会把前面的8k覆盖掉,不知道上面的程序又没有这样的问题。