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.start_with?("3")
raise FTPReplyError, resp
end
end
resp = sendcmd(cmd)
resp = getresp if resp.start_with?("2")
if !resp.start_with?("1")
raise FTPReplyError, resp
end
else
sock = makeport
begin
addr = sock.local_address
sendport(addr.ip_address, addr.ip_port)
if @resume and rest_offset
resp = sendcmd("REST " + rest_offset.to_s)
if !resp.start_with?("3")
raise FTPReplyError, resp
end
end
resp = sendcmd(cmd)
resp = getresp if resp.start_with?("2")
if !resp.start_with?("1")
raise FTPReplyError, resp
end
conn, = sock.accept
sock.shutdown(Socket::SHUT_WR) rescue nil
sock.read rescue nil
ensure
sock.close
end
end
if @private_data_connection
return BufferedSSLSocket.new(start_tls_session(conn),
read_timeout: @read_timeout)
else
return BufferedSocket.new(conn, read_timeout: @read_timeout)
end
end