rendered paste bodyproc sockConnected {sock file} { global total done size fileevent $sock writable {} if {![eof $sock]&&[fconfigure $sock -error]==""} { # connected... open the file and start fcopy set out [open /tmp/[unixtime]-$file w] set in $sock set chunk 1024 set total 0 fcopy $in $out -command [list CopyMore $in $out $chunk] -size $chunk vwait done } else { # errors }}proc CopyMore {in out chunk bytes {error {}}} { global total done size incr total $chunk if {([string length $error] != 0) || [eof $in] || $total >= $size} { # file transfer is completed! set done $total close $in close $out } else { # continue copying fcopy $in $out -command [list CopyMore $in $out $chunk] \ -size $chunk }}