diff --git a/collects/tests/net/ftp.rkt b/collects/tests/net/ftp.rkt index 11554516dc..88ddaf0078 100644 --- a/collects/tests/net/ftp.rkt +++ b/collects/tests/net/ftp.rkt @@ -1,17 +1,215 @@ #lang racket (require net/ftp tests/eli-tester) -(define server "ftp.gnu.org") -(define port 21) -(define user "anonymous") -(define passwd "nonny") +(define (tcp-serve-port cop tp) + (define listener (tcp-listen 0)) + (define-values (_1 the-port _2 _3) (tcp-addresses listener #t)) + (values + (thread + (λ () + (define-values (ip op) (tcp-accept listener)) + (thread (λ () + (copy-port ip cop) + (flush-output cop) + (close-input-port ip))) + (thread (λ () + (copy-port tp op) + (close-output-port op))))) + the-port)) + +(define (ftp-port-split n) + (quotient/remainder n 256)) (provide tests) (define (tests) + (define cop (open-output-string)) + (define-values (pasv1-thread pasv1-port) + (tcp-serve-port (current-output-port) (open-input-string #< aspell/dict/csb +lrwxrwxrwx 1 0 0 14 Nov 24 2003 aspell-dict-ga -> aspell/dict/ga +lrwxrwxrwx 1 0 0 14 Mar 22 2004 aspell-dict-hr -> aspell/dict/hr +lrwxrwxrwx 1 0 0 14 Mar 12 2004 aspell-dict-is -> aspell/dict/is +lrwxrwxrwx 1 0 0 14 Nov 24 2003 aspell-dict-it -> aspell/dict/it +lrwxrwxrwx 1 0 0 14 Apr 26 2004 aspell-dict-sk -> aspell/dict/sk +drwxrwxr-x 13 0 1003 8192 Jul 03 14:05 auctex +drwxrwxr-x 2 0 1003 4096 Aug 02 18:10 autoconf +drwxr-xr-x 2 1003 1003 4096 Jul 06 14:30 autoconf-archive +drwxrwxr-x 32 0 1003 4096 Jul 25 18:10 autogen +drwxrwxr-x 2 0 1003 8192 Dec 08 2009 automake +drwxrwxr-x 2 0 1003 4096 Aug 26 2007 avl +drwxr-xr-x 2 1003 1003 4096 Jul 15 2009 ballandpaddle +drwxrwxr-x 2 0 1003 4096 Aug 02 2003 barcode +drwxrwxr-x 8 0 1003 4096 Jan 18 2010 bash +drwxrwxr-x 3 0 1003 8192 Jan 18 2007 bayonne +drwxrwxr-x 2 0 1003 4096 Aug 02 2003 bc +drwxrwxr-x 2 0 1003 4096 Mar 03 15:25 binutils +drwxrwxr-x 2 0 1003 4096 Aug 06 02:25 bison +drwxrwxr-x 2 0 1003 4096 Aug 02 2003 bool +drwxr-xr-x 10 1003 1003 4096 Jul 30 2007 bpel2owfn +-rw-r--r-- 1 1003 65534 420 Nov 15 2000 brl.README +drwxrwxr-x 2 0 1003 4096 Aug 02 2003 calc +drwxrwxr-x 2 0 1003 4096 Dec 16 2008 ccaudio +drwxrwxr-x 2 0 1003 4096 Oct 25 2009 ccrtp +drwxrwxr-x 2 0 1003 8192 May 19 00:50 ccscript +drwxrwxr-x 2 0 1003 4096 Aug 02 2003 cfengine +drwxr-xr-x 2 1003 1003 4096 Jul 11 2009 cflow +drwxrwxr-x 2 0 1003 4096 Nov 14 2009 cgicc +drwxrwxr-x 2 0 1003 4096 Jan 12 2004 chess +drwxrwxr-x 2 0 1003 4096 Aug 02 2003 cim +drwxrwxr-x 2 0 1003 4096 Mar 25 17:25 classpath +drwxrwxr-x 2 0 1003 4096 Apr 28 2007 classpathx +drwxrwxr-x 6 0 1003 4096 Jul 07 17:30 clisp +drwxrwxr-x 2 0 1003 4096 Aug 02 2003 clx +drwxr-xr-x 2 1003 1003 4096 Jun 05 2004 combine +lrwxrwxrwx 1 0 0 9 Nov 18 2003 commonc++ -> commoncpp +drwxrwxr-x 2 0 1003 8192 Aug 11 06:30 commoncpp +drwxrwxr-x 2 0 1003 4096 Feb 13 2008 config +drwxrwxr-x 2 0 1003 8192 Apr 23 16:45 coreutils +drwxrwxr-x 2 0 1003 4096 Mar 10 13:20 cpio +drwxrwxr-x 2 0 1003 4096 Aug 02 2003 cpp2html +drwxr-xr-x 2 1003 1003 4096 Mar 18 06:45 cppi +drwxr-xr-x 2 1003 1003 4096 Apr 11 2009 cssc +drwxrwxr-x 2 0 1003 4096 Feb 21 2008 dap +-rw-r--r-- 1 1003 65534 110 Jun 06 1999 dc.README +drwxrwxr-x 2 0 1003 4096 Feb 11 2009 ddd +drwxr-xr-x 2 1003 1003 4096 Apr 06 18:50 ddrescue +drwxrwxr-x 2 0 1003 4096 Jan 30 2004 dejagnu +drwxr-xr-x 2 1003 1003 4096 Jul 07 20:50 denemo +-rw-r--r-- 1 1003 65534 145 May 22 2001 dia.README +drwxr-xr-x 2 1003 1003 4096 Jul 07 19:35 dico +drwxrwxr-x 2 0 1003 4096 Sep 17 2007 diction +-rw-r--r-- 1 1003 65534 134 Apr 15 2002 dictionary.README +drwxrwxr-x 2 0 1003 4096 May 03 17:00 diffutils +drwxr-xr-x 2 1003 1003 4096 Apr 11 11:55 dionysus +drwxrwxr-x 2 0 0 4096 Apr 03 2007 dismal +-rw-r--r-- 1 1003 65534 492 Apr 03 2007 djgpp.README +drwxr-xr-x 2 1003 1003 4096 Feb 18 2005 dominion +drwxrwxr-x 5 0 1003 4096 Dec 10 2008 dotgnu +-rw-r--r-- 1 1003 65534 96 Feb 09 1999 dumb.README +drwxrwxr-x 2 0 1003 4096 Jul 10 2009 ed +drwxrwxr-x 2 0 1003 4096 Apr 08 18:05 edma +drwxrwxr-x 2 0 1003 4096 Feb 17 00:20 electric +-rw-r--r-- 1 1003 65534 835 Jan 24 1999 elisp-archive.README +drwxrwxr-x 3 0 1003 4096 May 08 04:01 emacs +drwxr-xr-x 2 1003 1003 4096 Sep 16 2008 emms +drwxrwxr-x 2 0 1003 4096 Jun 01 23:25 enscript +drwxr-xr-x 2 1003 1003 4096 Jan 26 2008 erc +drwxr-xr-x 2 1003 1003 4096 Jan 10 2010 fdisk +drwxr-xr-x 2 1003 1003 4096 Nov 16 2008 ferret +drwxrwxr-x 2 0 1003 4096 Jun 06 2009 findutils +drwxrwxr-x 2 0 0 4096 Mar 20 2007 flex +drwxrwxr-x 2 0 1003 4096 Aug 02 2003 fontutils +drwxr-xr-x 2 1003 1003 4096 Apr 20 21:05 freedink +drwxrwxr-x 2 0 1003 4096 Jan 04 2009 freefont +END + ))) + (define-values (pasv1-port-maj pasv1-port-min) + (ftp-port-split pasv1-port)) + (define-values (pasv2-thread pasv2-port) + (tcp-serve-port (current-output-port) (open-input-string #< #f + (test (ftp-port-split 18291) => (values 71 115) + (ftp-connection? 1) => #f (set! conn (ftp-establish-connection server port user passwd)) (ftp-connection? conn) (ftp-cd conn "gnu") @@ -25,4 +223,21 @@ (ftp-close-connection conn) (delete-file (build-path tmp-dir pth)) - (delete-directory/files tmp-dir))) \ No newline at end of file + (delete-directory/files tmp-dir) + + (get-output-string cop) => + #<