FtpSession constructor

FtpSession(
  1. Socket controlSocket, {
  2. String? username,
  3. String? password,
  4. required List<String> sharedDirectories,
  5. required ServerType serverType,
  6. required LoggerHandler logger,
  7. String? startingDirectory,
})

Implementation

FtpSession(this.controlSocket,
    {this.username,
    this.password,
    required this.sharedDirectories,
    required this.serverType,
    required this.logger,
    String? startingDirectory})
    : commandHandler = FTPCommandHandler(controlSocket, logger),
      fileOperations = VirtualFileOperations(sharedDirectories) {
  sendResponse('220 Welcome to the FTP server');
  // Set the starting directory if provided
  if (startingDirectory != null && fileOperations.exists(startingDirectory)) {
    try {
      fileOperations.changeDirectory(startingDirectory);
    } catch (e) {
      logger.generalLog('Failed to set starting directory: $e');
      sendResponse('550 Failed to set starting directory');
    }
  }

  controlSocket.listen(processCommand, onDone: closeConnection);
}