Private Sub sckDownload_DataArrival(ByVal bytesTotal As Long)
Dim Pos As Integer
Dim LENGTH As Integer
Dim HEAD As String
Debug.Print bytesTotal
Dim m_sData() As Byte
sckDownload.GetData m_sData(), vbByte
'sckDownload.GetData m_sDATA, vbString
Debug.Print "receiving data"
If InStr(LCase(m_sData), "content-type:") Then If RESUMEFILE = True Then 'check to see if its gonna resume ok or not..This is actually the worst way to check this.
If InStr(LCase(m_sData), "206 partial content") = 0 Then
MsgBox "Server did not accept resuming.", vbCritical, "No Resuming Support"
Reset
CloseSocket
Exit Sub
End If
End If
If InStr(LCase(m_sData), "404 not found") > 0 Then
MsgBox "The file requested was not found on the server!" & vbCrLf & vbCrLf & "Possible Reasons:" & vbCrLf & "- File Does Not Exist On Server" _
& vbCrLf & "- URL Given Was Script And Data Returned Was Invalid" & vbCrLf & "- URL Entered Was Incorrect" & vbCrLf & "- Server Is Excessively Busy" _
& vbCrLf & vbCrLf & "You may reattempt to download. If its still failure then most likely invalid url.", , "File Not Found"
Reset
CloseSocket
Exit Sub
End If
Pos = InStr(m_sData, vbCrLf & vbCrLf) ' find out where the header and the data is split apart
LENGTH = Len(CStr(m_sData)) 'get the length of the data chunk
HEAD = Left(m_sData, Pos - 1) 'Get the header from the chunk of data and ignore the data content
m_sData = Right(m_sData, LENGTH - Pos - 3) 'Get the data from the first chunk that contains the header also
Header = Header & HEAD 'Append the header to header text box
If RESUMEFILE = True Then
BytesAlreadySent = FileLength + 1
BytesRemaining = GETDATAHEAD(Header, "Content-Length:")
BytesRemaining = BytesRemaining + FileLength
Else
BytesRemaining = GETDATAHEAD(Header, "Content-Length:")
End If
Debug.Print "length: " & BytesRemaining
Debug.Print Header
End If
'-----------BEGIN WRITE CHUNK TO FILE CODE--------
Debug.Print "appending to file"
Open FilePathName For Binary Access Write As #1 'opens file for output
Put #1, BytesAlreadySent, m_sData 'writes data to the end of file
BytesAlreadySent = Seek(1)
Close #1 'close file for now until next data chunk is available
'--------------------------------------------------
If RESUMEFILE = False Then
transferrate = Format(Int(BytesAlreadySent / (Timer - BeginTransfer)) / 1000, "####.00")
Else
transferrate = Format(Int((BytesAlreadySent - FileLength) / (Timer - BeginTransfer)) / 1000, "####.00")
End If
Debug.Print "transfer rate: " & transferrate
End Sub
Private Sub sckDownload_Connect()
On Error Resume Next
Dim strCommand As String
Debug.Print "connected"
'Right(URL, Len(URL) - Len(strSvrURL) - 7)
strCommand = "GET " + URL + " HTTP/1.1" + vbCrLf
strCommand = strCommand + "Accept: video/mpeg , video/avi" + vbCrLf
If RESUMEFILE = True Then
strCommand = strCommand + "Range: bytes=" & FileLength & "-" & vbCrLf
End If
strCommand = strCommand + "User-Agent: Video Crawler" & vbCrLf
strCommand = strCommand + "Referer: " & strSvrURL & vbCrLf
strCommand = strCommand + "Host: " & strSvrURL & vbCrLf
strCommand = strCommand + vbCrLf
Debug.Print strCommand
sckDownload.SendData strCommand 'sends a header to the server instructing it what to do!
BeginTransfer = Timer 'start timer for transfer rate
End Sub