Skip to content
This repository has been archived by the owner on Mar 3, 2021. It is now read-only.

Added the storebinary method to the Server class #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ DEPENDENCIES
pry-nav
rake (>= 0.8.7)
rspec (> 2)

BUNDLED WITH
1.10.3
26 changes: 26 additions & 0 deletions lib/fake_ftp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,32 @@ def active?
@mode == :active
end

def storbinary(cmd, file, blocksize, rest_offset = nil) # :yield: data
if rest_offset
file.seek(rest_offset, IO::SEEK_SET)
end
synchronize do
with_binary(true) do
conn = transfercmd(cmd)
loop do
buf = file.read(blocksize)
break if buf == nil
conn.write(buf)
yield(buf) if block_given?
end
conn.close
voidresp
end
end
rescue Errno::EPIPE
# EPIPE, in this case, means that the data connection was unexpectedly
# terminated. Rather than just raising EPIPE to the caller, check the
# response on the control connection. If getresp doesn't raise a more
# appropriate exception, re-raise the original exception.
getresp
raise
end

private

def port_is_open?(port)
Expand Down