Hey all,

I've been trying to transfer some files between two networked computers using the code below. It works fine for simple text but JPEGs and I'm guessing other things don't work.

Could anybody please explain to me why this doesn't work for JPEGs and how I transfer JPEGs, EXEs, ZIPs using WinSock?


Public Sub SendData(sFile As String, sSaveAs As String, tcpCtl As Winsock)
On Error GoTo ErrHandler
Dim sSend As String, sBuf As String
Dim ifreefile As Integer
Dim lRead As Long, lLen As Long, lThisRead As Long, lLastRead As Long

ifreefile = FreeFile

' Open file for binary access:
Open sFile For Binary Access Read As #ifreefile
lLen = LOF(ifreefile)

' Loop through the file, loading it up in chunks of 64k:
Do While lRead < lLen
lThisRead = 65536
If lThisRead + lRead > lLen Then
lThisRead = lLen - lRead
End If
If Not lThisRead = lLastRead Then
sBuf = Space$(lThisRead)
End If
Get #ifreefile, , sBuf
lRead = lRead + lThisRead
sSend = sSend & sBuf
Loop
lTotal = lLen
Close ifreefile
bSendingFile = True
'// Send the file notification
tcpCtl.SendData "FILE" & sSaveAs
DoEvents: DoEvents: DoEvents: DoEvents

'// Send the file
DoEvents: DoEvents: DoEvents: DoEvents
ConnectToClient
tcpCtl.SendData sSend
DoEvents: DoEvents: DoEvents: DoEvents

'// Finished
DoEvents: DoEvents: DoEvents: DoEvents
ConnectToClient
tcpCtl.SendData "FILEEND"
DoEvents: DoEvents: DoEvents: DoEvents
bSendingFile = False
Exit Sub
ErrHandler:
MsgBox "Err " & Err & " : " & Error
End Subl


Thanks for your time,