Sample code for 30+ languages & platforms
Visual FoxPro

Receive a Block of Bytes to a File

See more Socket/SSL/TLS Examples

Demonstrates Socket.ReceiveBytesToFile, which receives one available block of bytes and appends it to a file.

The file path is relative to the application's current working directory. An absolute path may also be used. Supply the path appropriate to your own environment.

Background. Any buffered data is written first; otherwise a single receive operation is performed. The method appends, so repeated calls accumulate received blocks in the file.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loSocket
LOCAL lnBTls
LOCAL lnMaxWaitMs

lnSuccess = 0

loSocket = CreateObject('Chilkat.Socket')

*  Connect to the server using TLS.
lnBTls = 1
lnMaxWaitMs = 5000
lnSuccess = loSocket.Connect("example.com",5000,lnBTls,lnMaxWaitMs)
IF (lnSuccess = 0) THEN
    ? loSocket.LastErrorText
    RELEASE loSocket
    CANCEL
ENDIF

*  The file path is relative to the application's current working directory.  An absolute path
*  may also be used.  Supply the path appropriate to your own environment.

*  Receive one available block of bytes and append it to a file.  If bytes are already buffered,
*  they are used first; otherwise a single receive operation is performed.
lnSuccess = loSocket.ReceiveBytesToFile("qa_output/received.dat")
IF (lnSuccess = 0) THEN
    ? loSocket.LastErrorText
    RELEASE loSocket
    CANCEL
ENDIF

? "Received block appended to the file."

RELEASE loSocket