1 2(********************************************************************) 3(* *) 4(* ftpserv.sd7 FTP (file transfer protocol) server *) 5(* Copyright (C) 2011, 2012, 2017 Thomas Mertes *) 6(* *) 7(* This program is free software; you can redistribute it and/or *) 8(* modify it under the terms of the GNU General Public License as *) 9(* published by the Free Software Foundation; either version 2 of *) 10(* the License, or (at your option) any later version. *) 11(* *) 12(* This program is distributed in the hope that it will be useful, *) 13(* but WITHOUT ANY WARRANTY; without even the implied warranty of *) 14(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *) 15(* GNU General Public License for more details. *) 16(* *) 17(* You should have received a copy of the GNU General Public *) 18(* License along with this program; if not, write to the *) 19(* Free Software Foundation, Inc., 51 Franklin Street, *) 20(* Fifth Floor, Boston, MA 02110-1301, USA. *) 21(* *) 22(********************************************************************) 23 24 25$ include "seed7_05.s7i"; 26 include "ftpserv.s7i"; 27 28 29const proc: main is func 30 local 31 var string: parameter is ""; 32 var ftpServer: ftpServ is ftpServer.value; 33 var fileSys: backendSys is fileSys.value; 34 var listener: aListener is listener.value; 35 var file: existingConnection is STD_NULL; 36 var file: newConnection is STD_NULL; 37 begin 38 writeln("Ftpserv Version 1.0 - FTP (file transfer protocol) server"); 39 writeln("Copyright (C) 2011 Thomas Mertes"); 40 writeln("This is free software; see the source for copying conditions. There is NO"); 41 writeln("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."); 42 writeln("Ftpserv is written in the Seed7 programming language"); 43 writeln("Homepage: http://seed7.sourceforge.net"); 44 if length(argv(PROGRAM)) >= 1 then 45 parameter := argv(PROGRAM)[1]; 46 if length(argv(PROGRAM)) >= 2 and isDigitString(argv(PROGRAM)[2]) then 47 block 48 ftpServ.ftpControlPort := integer(argv(PROGRAM)[2]); 49 exception 50 catch RANGE_ERROR: writeln(" ***** Port number too big. Port " <& 51 ftpServ.ftpControlPort <& " used instead."); 52 end block; 53 end if; 54 end if; 55 if parameter in {"-h", "-?"} then 56 writeln; 57 writeln("usage: ftpserv [ftp-directory [port]]"); 58 else 59 ftpServ.backendSys := osFiles; 60 if parameter = "" then 61 ftpServ.startDirectory := getcwd(ftpServ.backendSys); 62 else 63 ftpServ.startDirectory := parameter; 64 end if; 65 writeln("FTP directory: " <& ftpServ.startDirectory); 66 writeln("Port: " <& ftpServ.ftpControlPort); 67 writeln("To test ftpserv you can call the ftp7 FTP client with:"); 68 writeln(" s7 ftp7 " <& getHostname <& " " <& ftpServ.ftpControlPort); 69 writeln("To stop ftpserv press CTRL-C."); 70 runServer(ftpServ); 71 end if; 72 end func; 73