REBOL [ Title: "REBOL/Services example file transfer client" Author: "Gabriele Santilli" Date: 17-Mar-2007 ] do %client.r chunk-size: 512 * 1024 upload-file: func [ "Upload a (large) file using the file service" service [url! block! port!] "Service to connect to" source-file [file! block! url! port!] "File to upload" dest-file [file!] "Destination path and file name" /local close? ] [ if not port? source-file [ source-file: open/binary/seek/read source-file close?: yes ] do-service service [file/put (dest-file) (copy/part source-file chunk-size)] source-file: skip source-file chunk-size while [not tail? source-file] [ do-service service [file/append (dest-file) (copy/part source-file chunk-size)] source-file: skip source-file chunk-size ] if close? [ close source-file ] ] check-result: func [result] [all [result/1 = 'done result/3 = 'ok next result/4]] download-file: func [ "Download a (large) file using the file service" service [url! block! port!] "Service to connect to" source-file [file!] "Path and name of the file to download" dest-file [file! block! url! port!] "File to save the download to" /local result pos bytes ] [ pos: 1 write/binary dest-file "" until [ either result: check-result do-service service [file/get (source-file) (pos) (chunk-size)] [ write/binary/append dest-file pick result 4 ] [ break ] pos: pos + chunk-size bytes: pick result 3 bytes < chunk-size ] ]