
FTP to SFTP (#1):

  https://www.bitvise.com/ftp-bridge
  https://enterprisedt.com/products/completeftp/doc/guide/html/gateway.html

  mindterm source (Java, FTPOverSFTP bridge code for mapping)

For each FTP command, decompose it into SFTP request equivalents; note which
FTP commands have no SFTP request equivalents.

  USER
  PASS
    USERAUTH
  ACCT
    n/a

  CWD
  XCWD
  CDUP
  XCUP
    n/a; will mod_proxy have to maintain some state about the FTP session
    for such directory traversal commands?  Yuck.  Maybe use with REALPATH?

  SMNT
    not implemented

  REIN
    not implemented

  QUIT
    CHANNEL_CLOSE

  PORT
  EPRT
  PASV
  EPSV
    this will be the most interesting; translating SFTP data transfers into
    frontend FTP transfers.

  TYPE
    n/a (binary only?)

  STRU
    n/a; always F

  MODE
    n/a; always S

  RANG
  REST
  RETR
    OPEN + READ + CLOSE

  RANG
  REST
  APPE
  STOR
    OPEN + WRITE + CLOSE

  STOU
    OPEN + WRITE + CLOSE; have mod_proxy generate the unique name for the
    backend SFTP file?  Use O_CREAT|O_EXCL to force uniqueness, I guess...

  ALLO
    n/a

  RNFR
  RNTO
    RENAME

  ABOR
    n/a; maybe just stop the current data transfer, send CLOSE?

  DELE
    REMOVE

  MDTM
    STAT

  MKD
  XMKD
    MKDIR

  RMD
  XRMD
    RMDIR

  LIST
  MLSD
  MLST
  NLST
    OPENDIR + READDIR + CLOSE

  MFF
    FSETSTAT
  MFMT
    FSETSTAT

  PWD
  XPWD

  SITE
    n/a; support for specific SITE commands *may* be added later, e.g.
    SITE CHMOD = SETSTAT
    SITE CHGRP = SETSTAT
    SITE SYMLINK = SYMLINK (from mod_site_misc)
    SITE UTIME = SETSTAT (from mod_site_misc)

  SIZE
    STAT

  SYST
    n/a; always "215 UNIX Type: L8"

  STAT
    STAT

  HELP
    n/a?

  NOOP
    no backend equivalent; handle in proxy

  FEAT
    n/a (SFTP extensions?)

  OPTS
  LANG
    n/a

  HOST
    n/a

  CLNT
    n/a (would be part of SSH connect, but is too late in FTP protocol)

  AUTH
  PBSZ
  PROT
    n/a (provided by SSH by default!)

For authentication, it will always be password authentication to the backend
SSH server.  (Or should this overridable, e.g. password authentication to
the proxy, but hostbased authentication from the proxy to the backend server?)

What does this look like, for an FTP forward proxy configuration to an SFTP
backend?  How would mod_proxy know that the destination server is an SFTP
server?  I suppose it could do a probe: make the initial TCP connection,
see whether it gets the "220 Server Ready" FTP response, or the "ssh-..."
SSH banner...

  Note: This would require that mod_proxy be built _without_ mod_sftp being
  present!  This means that the logic regarding mod_sftp HOOKs would need
  to be revisited.

  Implementation:
    Implement a "protocol", which handles all of the above FTP commands.
    The default Protocol object will do what mod_proxy currently does for
    all of the commands; this will thus be a transparent change.  These
    Protocol objects would then have to maintain/accumulate their own state,
    so as to implement/translate RNFR + RNTO = RENAME, *and* be responsible
    for translating the responses.  Thus these would indeed be more than
    just codecs (or, for some value of "codec", very complicated codecs).

    Once that's done, we need to determine how to lookup a new Protocol object,
    and when do it, and when to register it.  For cases where mod_proxy
    knows the backend URL at connect time, this is easier.   What about for
    the auth-time (PerUser, PerGroup) URLs?

    FTP Implementation API:
      Suitable for plugging into mod_proxy's CMD C_ANY handler, *and*
      its POST_CMD C_PROT handler.  Thus the API for the given impl
      input should be something like:

        MODRET (handle_cmd)(pool *p, cmd_rec *cmd, int cmd_phase);

      Consider, for example, a logging-only Implementation object, to
      demonstrate the concept?

    Note that this Impl API works for FTP, but NOT for SSH; SSH packets
    are not handled by the C_ANY handler.

SFTP to FTP (#2):

  No forward proxying supported here, since SFTP doesn't have that notion;
  mod_proxy will know (via the ProxyReversServers URL schemes) which protocol
  to use for the backend server.

SCP (#3?):
  subset of SFTP to FTP, with no directory listing support.
