Warning, /frameworks/kio/autotests/ftpd is written in an unsupported language. File is not indexed.
0001 #!/usr/bin/env ruby 0002 # SPDX-FileCopyrightText: 2019 Harald Sitter <sitter@kde.org> 0003 # 0004 # SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 0006 require 'ftpd' 0007 require 'logger' 0008 require 'tmpdir' 0009 0010 STDOUT.sync = true 0011 0012 # Monkey patch the site handler, it's not implemented so fake it a bit for ftp 0013 # worker purposes. 0014 0015 # FIXME: and yet I seee kio_ftp(8319)/(kf5.kio.kio_ftp) Ftp::ftpChmod: ftpChmod: CHMOD not supported - disabling 0016 0017 module Ftpd 0018 class CmdSite 0019 alias cmd_site_orig cmd_site 0020 def cmd_site(_argument) 0021 # We don't support chmod bugger off. 0022 reply '500 cmd_site.' 0023 end 0024 end 0025 end 0026 0027 module Ftpd 0028 class CmdRest 0029 def cmd_rest(_argument) 0030 reply "350 cmd_rest." 0031 end 0032 end 0033 end 0034 0035 module Ftpd 0036 class CmdStor 0037 alias cmd_stor_orig cmd_stor 0038 def cmd_stor(argument) 0039 if argument.include?('__badResume__') 0040 reply '550 out of quota' 0041 else 0042 cmd_stor_orig(argument) 0043 end 0044 end 0045 end 0046 end 0047 0048 # Add some simulation capabilities to the file system 0049 class MangledDiskFileSystem < Ftpd::DiskFileSystem 0050 def accessible?(path, *args) 0051 return false if path.include?('__inaccessiblePath__') 0052 0053 super(path, *args) 0054 end 0055 end 0056 0057 class Driver 0058 def initialize(temp_dir) 0059 @temp_dir = temp_dir 0060 end 0061 0062 def authenticate(_user, _password) 0063 true 0064 end 0065 0066 def file_system(_user) 0067 MangledDiskFileSystem.new(@temp_dir) 0068 end 0069 end 0070 0071 # NB: stderr is used to communicate with the parent! 0072 0073 port = ARGV.fetch(0) 0074 temp_dir = ARGV.fetch(1) 0075 0076 driver = Driver.new(temp_dir) 0077 server = Ftpd::FtpServer.new(driver) 0078 server.port = port 0079 server.log = Logger.new($stdout) 0080 server.start 0081 warn "port = #{server.bound_port}" 0082 puts "Server listening on port #{server.bound_port}" 0083 loop do 0084 sleep(1) 0085 end