ftp: fix an error (#7930)
parent
2ad2d68d7c
commit
ad79d55a5c
|
@ -32,9 +32,6 @@ pub fn new_buffered_reader(o BufferedReaderConfig) &BufferedReader {
|
|||
|
||||
// read fufills the Reader interface
|
||||
pub fn (mut r BufferedReader) read(mut buf []byte) ?int {
|
||||
if r.end_of_stream {
|
||||
return none
|
||||
}
|
||||
// read data out of the buffer if we dont have any
|
||||
if r.needs_fill() {
|
||||
if !r.fill_buffer() {
|
||||
|
@ -53,7 +50,7 @@ fn (mut r BufferedReader) fill_buffer() bool {
|
|||
if r.end_of_stream {
|
||||
// we know we have already reached the end of stream
|
||||
// so return early
|
||||
return false
|
||||
return true
|
||||
}
|
||||
r.offset = 0
|
||||
r.len = 0
|
||||
|
@ -117,4 +114,3 @@ pub fn (mut r BufferedReader) read_line() ?string {
|
|||
r.offset = i
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,8 +43,15 @@ mut:
|
|||
}
|
||||
|
||||
fn (mut dtp DTP) read() ?[]byte {
|
||||
mut data := []byte{len: 1024}
|
||||
dtp.reader.read(mut data) ?
|
||||
mut data := []byte{}
|
||||
mut buf := []byte{len: 1024}
|
||||
for {
|
||||
len := dtp.reader.read(mut buf) or { break }
|
||||
if len == 0 {
|
||||
break
|
||||
}
|
||||
data << buf[..len]
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
|
@ -163,22 +170,22 @@ pub fn (mut ftp FTP) cd(dir string) ? {
|
|||
}
|
||||
}
|
||||
|
||||
fn new_dtp(msg string) ?DTP {
|
||||
fn new_dtp(msg string) ?&DTP {
|
||||
if !is_dtp_message_valid(msg) {
|
||||
return error('Bad message')
|
||||
}
|
||||
ip, port := get_host_ip_from_dtp_message(msg)
|
||||
conn := net.dial_tcp('$ip:$port') or { return error('Cannot connect to the data channel') }
|
||||
dtp := DTP{
|
||||
conn: conn
|
||||
reader: io.new_buffered_reader(reader: io.make_reader(conn))
|
||||
mut dtp := &DTP{
|
||||
ip: ip
|
||||
port: port
|
||||
}
|
||||
conn := net.dial_tcp('$ip:$port') or { return error('Cannot connect to the data channel') }
|
||||
dtp.conn = conn
|
||||
dtp.reader = io.new_buffered_reader(reader: io.make_reader(dtp.conn))
|
||||
return dtp
|
||||
}
|
||||
|
||||
fn (mut ftp FTP) pasv() ?DTP {
|
||||
fn (mut ftp FTP) pasv() ?&DTP {
|
||||
ftp.write('PASV') ?
|
||||
code, data := ftp.read() ?
|
||||
$if debug {
|
||||
|
|
Loading…
Reference in New Issue