Hi There,
I am using VB6 and Winsock to send and receive encrypted files to and from a remote server. Winsock works fine for this except when the remote server sends multiple files to me.
My program will receive the first file just fine, however all the subsequent files have seem to have two extra bytes added to the file. If I open the file up in a text editor and remove the bytes, the file will open up fine. It is just a pain to have to open all files and remove these bytes.
Here is the DataArrival code:
Any thoughts on why this is happening? Thanks in advance for any insight you can offer.
I am using VB6 and Winsock to send and receive encrypted files to and from a remote server. Winsock works fine for this except when the remote server sends multiple files to me.
My program will receive the first file just fine, however all the subsequent files have seem to have two extra bytes added to the file. If I open the file up in a text editor and remove the bytes, the file will open up fine. It is just a pain to have to open all files and remove these bytes.
Here is the DataArrival code:
Code:
Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
Dim hFile As Long
Winsock.GetData strData, vbString, bytesTotal
' If we're not in a file transfer operation, this could well be a "BOF".
If (Not blnConnected) Then
'
If (Mid$(strData, 1, 3) = "BOF") Then
' We have an incoming file - save the filename, and set the operation
' flag so that next time data arrives (file data) it will be saved.
blnConnected = True
m_strFilename = Mid$(strData, 4)
' Send back a "NEXT" to get some of the file data.
Call Winsock.SendData("NEXT")
DoEvents
End If
Else
' If we're already in a transfer, this data could either be file data, or
' an EOF marker.
If (Mid$(strData, 1, 3) = "EOF") Then
'
' The transfer is complete.
blnConnected = False
DoEvents
'
Else
' Open a temporary file in the current directory - this is where all the
' file data is saved.
hFile = FreeFile
Open outputFileName For Binary As #hFile
' Move to the end of the file, and write the data.
Seek #hFile, LOF(hFile) + 1
Put #hFile, , strData
'
Close #hFile
'
' Send the server another "NEXT" command to get the next piece of data.
Call Winsock.SendData("NEXT")
DoEvents
'
End If
'
End If
End Sub
Any thoughts on why this is happening? Thanks in advance for any insight you can offer.