Remote File Copy


This program demonstrates sending and receiving an entire file using TCP\IP sockets.

It also demonstrates concurrent socket handling within Visual BASIC 6. The Winsock Control is used for simplicity. It implements a simple protocol for passing header information and basic error control.

This program was written to implement a DCC Send style function.
The protocol is very simple for implementation in other programming languages (e.g. C++, Java and C#).


A custom format has been used to allow proper read synchronisation.

12 bytes : 0 extended decimal file name length in bytes (string, e.g. '000000000010'=n)
n bytes : file name (string, e.g. 'winzip.log')
12 bytes : 0 extended decimal file length in bytes (string, e.g. '000000125531'=m)

m bytes : {file body}



1. Press start to start the listener (if client),
2. Enter the filename to transfer, remote host and port number on the sender,
3. Press send to transfer the file.

The program uses port 1000, configurable on the form. The listener must be running before the server connects.

Implementation details

A hidden form is used with a Winsock control to receive incoming data for the client. A hard coded limit of 100 simultaneous connections has been set in the program.
A small read buffer is used in the sender to prevent excessive memory use when copying large files.


1. During development it was observed that when the sender has finished sending and the socket is closed, a socket close event is raised in the client even though it may still be receiving data. In this case the socket close attempt is ignored by the client. The socket is now closed by the client when the last data arrived event occurs.
2. The program will only read the exact number of bytes transmitted as specified in the header. Extra bytes or interrupted transmission may cause the program to end up trying to read the body of a file when a header is expected. If this happens you must stop and start the listener.


Version 0.8

bug fixes:
1. extra null data was caused by reading an extra chunk due to VB arithmetic round up error,
2. race condition fixed by client closing the socket when all data has arrived, not the server.

performance improvements:
1. only reallocate read buffer if more data arrives than previously allocated
each data arrived event can get a different number of pending bytes potentially,
we keep the buffer set to the highest number received so far for efficiency.
2. read chunk size increased to 32000 bytes.

user interface improvements:
1. file browse button added,
2. doevents used in sender to yield to other threads.

Version 0.7
1. block socket close attempt from server when client is still receiving.
Version 0.6
1. sender doesn't send whole path, just filename,
2. version number set correctly.
Version 0.5
1. Last packet size read correction,
2. copy filename from source for output file.


Download available from the download section.

Back to index.