Hai ragione oregon, ecco il codice:
Questi sono i dati in arrivo al client:
codice:
Private Sub CLIENT_DataArrival(ByVal bytesTotal As Long)
On Error Resume Next
Dim strData As String
Dim strDataSave As String
Dim sFile As String: Dim pFile As String
CLIENT.GetData strData, vbString
Select Case Mid(strData, 1, 15)
Case "SENDING_H_FILE:"
'Open File:
frmDownload.Timer.Enabled = True 'attiva timer.
Close #1: 'chiudi in caso sia aperto.
sFile = Split(Mid(strData, 16), vbCrLf)(0)
pFile = frmDownload.tFolder.Text & sFile
lngFile = Split(Mid(strData, Len(sFile) + 19), "]")(0)
If Dir(pFile) <> "" Then
Kill pFile
End If
frmDownload.Show
frmDownload.tFile.Caption = "File: " & sFile
Open pFile For Binary As #1
If lngFile = 0 Then
Close #1
frmDownload.PBAR.Value = 100
Call SetEndDownload
Exit Sub
End If
frmDownload.PBAR.Max = lngFile
CLIENT.SendData "FILE_OPENED."
Case "DOWNLOAD_ERROR:"
CancelDownload = 0
Unload frmDownload
MsgBox Mid(strData, 16), vbCritical, "Download Error:"
End Select
If InStr(strData, ">>>..HFILE..>>>") Then
'Put in file:
strDataSave = Replace$(strData, ">>>..HFILE..>>>", "")
Put #1, , strDataSave
frmDownload.PBAR.Value = LOF(1)
frmDownload.Caption = "Download - " & Int((LOF(1) * 100) / lngFile) & "% - ...in corso..."
frmDownload.tBytes.Caption = "Bytes scaricati: " & LOF(1) & " di " & lngFile
If LOF(1) = lngFile Then
Close #1
Call SetEndDownload
End If
End If
Select Case Mid(strData, 1, 13)
Dim pRoots As String
Dim pFolders As String
Dim pFiles As String
Case "LIST_DRIVERS:"
pRoots = Mid(strData, 14)
Call SetRoots(pRoots)
Case "LIST_FOLDERS:"
pFolders = Split(Mid(strData, 14), "LIST_FILES:")(0)
pFiles = Split(strData, "LIST_FILES:")(1)
Grid.ClearStructure: Grid.Rows = 2
Call SetFlex(pFolders, vbDirectory)
Call SetFlex(pFiles, vbNormal)
End Select
ServerResponded = True
End Sub
QUESTA LA FUNZIONE CHE INVIA I DATA DAL SERVER:
Private Sub SEND_BINARY_FILE()
On Error Resume Next
Dim strData As String
Dim spaceRemaining As Long
Dim allspaceget As Long
Dim lngfile_o As Long
Dim getlng As Long
lngfile_o = FileLen(pFile)
spaceRemaining = lngfile_o
getlng = 8192 - 30
Open pFile For Binary As #1
If Err Then
SERVER.SendData "DOWNLOAD_ERROR:Accesso Negato. Impossibile scaricare il file."
Close #1: Exit Sub
End If
Dim strToSend As String
Do Until (allspaceget >= lngfile_o)
If ((spaceRemaining) <= getlng) Then
getlng = (spaceRemaining)
End If
strData = Space$(getlng)
Get #1, , strData
strToSend = ">>>..HFILE..>>>" & strData & ">>>..HFILE..>>>"
SERVER.SendData strToSend
allspaceget = allspaceget + getlng
spaceRemaining = lngfile_o - allspaceget
DoEvents
Loop
Close #1