#!/usr/bin/perl5.8.8 -w use strict; use warnings; use threads; use IO::Socket qw(:DEFAULT :crlf); my $host = shift || 'localhost'; my $socket = IO::Socket::INET->new(PeerAddr => $host, PeerPort => 'ftp', Proto => 'tcp', Type => SOCK_STREAM, Timeout => 5) or die "Couldn't connect to remote host: $@\n"; my $listenerThread = threads->create(\&listener, $socket) or die "$@\n"; while () { chomp; print $socket $_, CRLF; }; exit(0); sub listener($) { my $s = shift; my $data; $/ = CRLF; syswrite(STDOUT, $data) while sysread($s, $data, 2048); print "\nListener exiting\n"; }; __END__