eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'AbstractFTPSession':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: AbstractFTPSession


Inheritance:

   Object
   |
   +--AbstractTCPSession
      |
      +--AbstractFTPSession
         |
         +--FTPSession
         |
         +--SmalltalkFTPSession

Package:
stx:goodies/communication
Category:
Net-Communication-FTP
Version:
rev: 1.33 date: 2024/03/26 12:58:44
user: cg
file: AbstractFTPSession.st directory: goodies/communication
module: stx stc-classLibrary: communication

Description:


Helper class for the FTPServer.

Common code for FTP serverSessions - add concrete subclass
The stuff implemented here realizes the protocol;
real file operations and authorization must be implemented in subclasses.

Methods which should be redefined are found in the 'must be redefined' category.

Be aware, that FTPSessions may allow a client to GET all files
which are readable by me (except for the white- and blacklists below).

To limit access to certain folders, you can explicitly whiteList
allowed folders (by setting whiteListedFolders) and/or exclude individual folders
via a blackList (setting blackListedFolders).

Whitelisting is done first, then blacklisting
i.e. it is possible to allow everything under '/foo/...' by adding '/foo' to the whitelist,
and still exclude individual subdirectories under it by adding (say) '/foo/bar/baz' to the blacklist.


    
    FTPServer start.
    FTPServer startOnPort:portNr.

    (FTPServer forPort:12345)
        sessionClass:SmalltalkFTPSession;
        start

    then, on the command line, try:
        ftp loalhost 12345

copyright

COPYRIGHT (c) 2003 by eXept Software AG All Rights Reserved This software is furnished under a license and may be used only in accordance with the terms of that license and with the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred.

protocol

List of commands supported by this session framework (however, subclasses may extend this by (re-)defining listOfSupportedCommands and implementing a corresponding method. Command Supported Notes ----------------------------------------- ABOR - ACCT - ADAT - ALLO - APPE - CCC - CDUP Yes CONF - CWD Yes DELE Yes ENC - EPRT - EPSV Yes FEAT Yes HELP Yes HOST - LANG - LIST Yes LPRT - LPSV - MDTM - MIC - MKD Yes MLSD - MLST - MODE - NLST Yes NOOP Yes OPTS - PASS Yes PASV Yes PBSZ - PORT Yes PROT - PWD Yes QUIT Yes REIN Yes REST - RETR Yes RMD Yes RNFR - RNTO - SITE Yes SIZE - SMNT - STAT Yes STOR Yes STOU Yes STRU - SYST Yes TYPE Yes USER Yes XCUP - XMKD - XPWD - XRMD - XRSQ - XSEM - XSEN -

Class protocol:

defaults
o  ftpVersion

queries
o  isAbstract
Return if this class is an abstract class.
True is returned here for myself only; false for subclasses.
Abstract subclasses must redefine this again.


Instance protocol:

accessing
o  allowOnlyEPSV
if set to true, all data connections but EPASV are rejected

o  blackListedFoldersForReading
if non-nil, folders whose names match any in the given list will
NOT be visible to clients

o  blackListedFoldersForReading: aListOfGlobPatterns
if non-nil, folders whose names match any in the given list will
NOT be visible to clients

o  blackListedFoldersForWriting
if non-nil, folders whose names match any in the given list will
NOT be allowed to be written into by clients

o  blackListedFoldersForWriting: aListOfGlobPatterns
if non-nil, folders whose names match any in the given list will
NOT be allowed to be written into by clients

o  exitOnBadCommand: aBoolean
can be set to enforce connection closing, whenever a bad command arrives

o  whiteListedFoldersForReading
if non-nil, only folders whose names match any in the given list will
be visible to clients

o  whiteListedFoldersForReading: aListOfGlobPatterns
if non-nil, only folders whose names match any in the given list will
be visible to clients

o  whiteListedFoldersForWriting
if non-nil, only folders whose names match any in the given list will
NOT be allowed to be written into by clients

o  whiteListedFoldersForWriting: aListOfGlobPatterns
if non-nil, only folders whose names match any in the given list will
NOT be allowed to be written into by clients

debugging
o  logCommand: aMessage

ftp system commands
o  EPSV
incoming EPASV command.
Open a listening socket on a random port,
wait for the session partner to connect to it.
Timeout after some time, if he does not connect to me.
(separate data connection)

o  FEAT
return list of features

Usage example(s):

^ socket nextPutLine:('501 FEAT command syntax')

o  HELP
send all commands supported by FTP server

o  LPSV
incoming LPSV command.
Open a listening socket on a random port,
wait for the session partner to connect to it.
Timeout after some time, if he does not connect to me.
(separate data connection)

o  NOOP
no instruction command

o  PASS
password from user; already read in from USER command

o  PASV
incoming PASV command.
Open a listening socket on a random port,
wait for the session partner to connect to it.
Timeout after some time, if he does not connect to me.
(separate data connection)

o  PORT
incoming PORT command.
Connect to the session partner (separate data connection)

o  QUIT
shutdown session

o  REIN
reinitialize session

o  SITE
incoming SITE command.
sends back some statistic info;
or allows the idle timeout to be changed (SITE IDLE <seconds>)

o  STAT
incoming STAT command.
sends back some statistic info

o  SYST
incoming SYST command.
send back the system type

o  USER
incoming USER command.
login to a new session

ftp user commands
o  CDUP
change to parent directory

o  CWD
change working directory

o  DELE
delete file or (empty) directory

o  LIST
show directory contents; longFormat

o  MKD
make directory

o  NLST
show directory contents; shortFormat

o  PWD
get current working directory

o  RETR
incoming RETR command.
retrieve a file (i.e. download as seen from client)

o  RMD
recursive delete directory

o  STOR
incoming STOR command.
upload as seen from ftp client

o  STOU
incoming STOU command.
upload as seen from ftp client

o  TYPE
set mode:
bin (I or i) := #binary
ascii(A or a) := #ascii

must be redefined
o  canChangeWorkingDirectory: newDirectory
raise an error: must be redefined in concrete subclass(es)

** This method must be redefined in concrete classes (subclassResponsibility) **

o  checkPassword: arg1 for: arg2
raise an error: must be redefined in concrete subclass(es)

** This method must be redefined in concrete classes (subclassResponsibility) **

o  defaultDirectoryForUser: userName
raise an error: must be redefined in concrete subclass(es)

** This method must be redefined in concrete classes (subclassResponsibility) **

o  doDELETE: recursive
raise an error: must be redefined in concrete subclass(es)

o  doLIST: arg
raise an error: must be redefined in concrete subclass(es)

o  doMKD: arg
raise an error: must be redefined in concrete subclass(es)

o  doRETR: file onTo: outStream
raise an error: must be redefined in concrete subclass(es)

o  doSTORE: arg
raise an error: must be redefined in concrete subclass(es)

o  loginUserNeedsPassword: arg
raise an error: must be redefined in concrete subclass(es)

** This method must be redefined in concrete classes (subclassResponsibility) **

private
o  closeDataConnection

o  doReinitialize
reinitialize the system; called when:
- user logged out
- system before shutdown
- reinitialize request
- during startup

o  doUserLoggedIn: aUser
setup user context

o  listOfSupportedCommands
^ self class methodDictionary keys

o  listOfSupportedFeatures

o  nextCommand
reads the next command from socket; if a timeout occurs nil is returned otherwise
the command as string and the lastArgument is set to the received argument

o  serveNextCommandFromSocket
make sure that nobody sends funny messages to me or my superclass

o  serveSocket: aSocket
(comment from inherited method)
redefine in concrete classes to something like:

private ftp
o  checkAndGetArgFilename

o  checkAndGetCWD

o  checkAndGetDataConnection

protocol testing
o  allowedToSeeDirectory: dir
|ftp|
ftp := FTPSession basicNew.
ftp whiteListedFoldersForReading:#( '/foo' '/bar*' ).
ftp blackListedFoldersForReading:#( '/foo/bar' '/bar/baz/').
self assert:( ftp allowedToSeeDirectory:'/foo' ).
self assert:( ftp allowedToSeeDirectory:'/fooo' ) not.
self assert:( ftp allowedToSeeDirectory:'/foo/bar' ) not.
self assert:( ftp allowedToSeeDirectory:'/foo/baz' ).

o  allowedToWriteIntoDirectory: dir
|ftp|
ftp := FTPSession basicNew.
ftp whiteListedFoldersForWriting:#( '/foo' '/bar*' ).
ftp blackListedFoldersForWriting:#( '/foo/bar' '/bar/baz/').
self assert:( ftp allowedToWriteIntoDirectory:'/foo' ).

o  isPath: aFilename inList: aWhiteOrBlackList
|ftp|
ftp := FTPSession basicNew.
self assert:( ftp isPath:'/foo' inList:#( '/foo' '/bar*' ) ).
self assert:( ftp isPath:'/barr' inList:#( '/foo' '/bar*' ) ).
self assert:( ftp isPath:'/bar/bla' inList:#( '/foo' '/bar*' ) ).
self assert:( ftp isPath:'/baz' inList:#( '/foo' '/bar*' ) ) not.
self assert:( ftp isPath:'/fooo' inList:#( '/foo' '/bar*' ) ) not.
self assert:( ftp isPath:'/fooo' inList:#( '/foo*' '/bar*' ) ).

queries
o  isBinary

serving
o  clientOn: aSocket
process for new client



ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sat, 21 Dec 2024 14:54:52 GMT