Copy a Large File

For making backups, it is a common problem to copy a large tar file from one machine to another in the same network. Normally I would use commands like:

SourceServer> ncat -l --send-only 1701 < backup.tgz
DestinClient> ncat SourceServer 1701 > backup.tgz

Then compare the checksums:

DestinClient> cksum backup.tgz

This is taken from the NMap group. Recently a problem came up where the client did not have ncat, I thought to use Pharo instead so the client code is below (lifted from the SocketStream class comment):

| file socketStream result blocksize writeStream |
blocksize := 1024.
file := File openForWriteFileNamed: 'backup.tgz'.
	socketStream := SocketStream openConnectionToHostNamed: '' port: 1701.
	[ [ socketStream binary.
		[ socketStream atEnd ]  whileFalse: [
			result := socketStream next: blocksize.
			file nextPutAll: result ] ]
	ensure: [ socketStream close ] ]
				on: ConnectionTimedOut
		do: [:ex | Transcript show: ex asString; cr. ex resume]
] ensure: [ file close ]

The address '' needs to be changed to the IP where the ncat listener is already running once local testing is done.

Posted by John Borden at 11 March 2023, 4:57 pm link