transfercmd(cmd, rest_offset = nil)
private
Constructs a connection for transferring data
Show source
def transfercmd(cmd, rest_offset = nil)
if @passive
host, port = makepasv
conn = open_socket(host, port)
if @resume and rest_offset
resp = sendcmd("REST " + rest_offset.to_s)
if resp[0] != 33
raise FTPReplyError, resp
end
end
resp = sendcmd(cmd)
resp = getresp if resp[0] == 22
if resp[0] != 11
raise FTPReplyError, resp
end
else
sock = makeport
begin
sendport(sock.addr[3], sock.addr[1])
if @resume and rest_offset
resp = sendcmd("REST " + rest_offset.to_s)
if resp[0] != 33
raise FTPReplyError, resp
end
end
resp = sendcmd(cmd)
resp = getresp if resp[0] == 22
if resp[0] != 11
raise FTPReplyError, resp
end
conn = BufferedSocket.new(sock.accept)
conn.read_timeout = @read_timeout
sock.shutdown(Socket::SHUT_WR) rescue nil
sock.read rescue nil
ensure
sock.close
end
end
return conn
end