Sha256: 8750ab2507627a54bfeb9af0ec0d7ad5d611ef525d84d405351968ffa1fd9cf4

Contents?: true

Size: 897 Bytes

Versions: 6

Compression:

Stored size: 897 Bytes

Contents

# frozen_string_literal: true

module FakeFtp
  module ServerCommands
    class Retr
      def run(ctx, filename = '', *)
        ctx.respond_with('501 No filename given') if filename.empty?

        f = ctx.file(filename.to_s)
        return ctx.respond_with('550 File not found') if f.nil?

        if ctx.active? && ctx.command_state[:active_connection].nil?
          ctx.respond_with('425 Ain\'t no data port!')
          return
        end

        ctx.respond_with('150 File status ok, about to open data connection')
        data_client = if ctx.active?
                        ctx.command_state[:active_connection]
                      else
                        ctx.data_server.accept
                      end

        data_client.write(f.data)

        data_client.close
        ctx.command_state[:active_connection] = nil
        '226 File transferred'
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
vagrant-unbundled-2.0.2.0 vendor/bundle/ruby/2.4.0/gems/fake_ftp-0.3.0/lib/fake_ftp/server_commands/retr.rb
vagrant-unbundled-2.0.1.0 vendor/bundle/ruby/2.4.0/gems/fake_ftp-0.3.0/lib/fake_ftp/server_commands/retr.rb
vagrant-unbundled-2.0.0.1 vendor/bundle/ruby/2.4.0/gems/fake_ftp-0.3.0/lib/fake_ftp/server_commands/retr.rb
vagrant-unbundled-1.9.8.1 vendor/bundle/ruby/2.4.0/gems/fake_ftp-0.3.0/lib/fake_ftp/server_commands/retr.rb
vagrant-unbundled-1.9.7.1 vendor/bundle/ruby/2.4.0/gems/fake_ftp-0.3.0/lib/fake_ftp/server_commands/retr.rb
fake_ftp-0.3.0 lib/fake_ftp/server_commands/retr.rb