Class: FakeFtp::ServerCommands::Rnto

Inherits:
Object
  • Object
show all
Defined in:
lib/fake_ftp/server_commands/rnto.rb

Instance Method Summary collapse

Instance Method Details

#run(ctx, rename_to = '') ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/fake_ftp/server_commands/rnto.rb', line 6

def run(ctx, rename_to = '', *)
  return '501 Send path name.' if rename_to.nil? || rename_to.empty?
  return '503 Send RNFR first.' if ctx.command_state[:rename_from].nil?

  f = ctx.file(ctx.command_state[:rename_from])
  if f.nil?
    ctx.command_state[:rename_from] = nil
    return '550 File not found.'
  end

  f.name = rename_to
  ctx.command_state[:rename_from] = nil
  '250 Path renamed.'
end