mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
5683af821e
commit
f751271e4e
@ -17,7 +17,6 @@ basic ftp module
|
||||
dtp.close()
|
||||
ftp.close()
|
||||
*/
|
||||
|
||||
import net
|
||||
import io
|
||||
|
||||
@ -94,13 +93,12 @@ fn (mut ftp FTP) read() ?(int, string) {
|
||||
}
|
||||
|
||||
pub fn (mut ftp FTP) connect(ip string) ?bool {
|
||||
conn := net.dial_tcp('$ip:21')?
|
||||
ftp.conn = conn
|
||||
ftp.conn = net.dial_tcp('$ip:21') ?
|
||||
ftp.reader = io.new_buffered_reader(reader: io.make_reader(ftp.conn))
|
||||
code, _ := ftp.read() ?
|
||||
if code == connected {
|
||||
return true
|
||||
}
|
||||
ftp.reader = io.new_buffered_reader(reader: io.make_reader(ftp.conn))
|
||||
return false
|
||||
}
|
||||
|
||||
@ -147,9 +145,7 @@ pub fn ( mut ftp FTP) pwd() ?string {
|
||||
}
|
||||
|
||||
pub fn (mut ftp FTP) cd(dir string) ? {
|
||||
ftp.write('CWD $dir') or {
|
||||
return
|
||||
}
|
||||
ftp.write('CWD $dir') or { return }
|
||||
mut code, mut data := ftp.read() ?
|
||||
match int(code) {
|
||||
denied {
|
||||
@ -172,11 +168,10 @@ fn new_dtp(msg string) ?DTP {
|
||||
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')
|
||||
}
|
||||
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))
|
||||
ip: ip
|
||||
port: port
|
||||
}
|
||||
@ -184,8 +179,7 @@ fn new_dtp(msg string) ?DTP {
|
||||
}
|
||||
|
||||
fn (mut ftp FTP) pasv() ?DTP {
|
||||
ftp.write('PASV') or {
|
||||
}
|
||||
ftp.write('PASV') ?
|
||||
code, data := ftp.read() ?
|
||||
$if debug {
|
||||
println('pass: $data')
|
||||
@ -198,22 +192,19 @@ fn ( mut ftp FTP) pasv() ?DTP {
|
||||
}
|
||||
|
||||
pub fn (mut ftp FTP) dir() ?[]string {
|
||||
mut dtp := ftp.pasv() or {
|
||||
return error('cannot establish data connection')
|
||||
}
|
||||
ftp.write('LIST') or {
|
||||
}
|
||||
mut dtp := ftp.pasv() or { return error('Cannot establish data connection') }
|
||||
ftp.write('LIST') ?
|
||||
code, _ := ftp.read() ?
|
||||
if code == denied {
|
||||
return error('LIST denied')
|
||||
return error('`LIST` denied')
|
||||
}
|
||||
if code != open_data_connection {
|
||||
return error('data channel empty')
|
||||
return error('Data channel empty')
|
||||
}
|
||||
list_dir := dtp.read() ?
|
||||
result, _ := ftp.read() ?
|
||||
if result != close_data_connection {
|
||||
println('LIST not ok')
|
||||
println('`LIST` not ok')
|
||||
}
|
||||
dtp.close()
|
||||
mut dir := []string{}
|
||||
@ -228,11 +219,8 @@ pub fn ( mut ftp FTP) dir() ?[]string {
|
||||
}
|
||||
|
||||
pub fn (mut ftp FTP) get(file string) ?[]byte {
|
||||
mut dtp := ftp.pasv() or {
|
||||
return error('Cannot stablish data connection')
|
||||
}
|
||||
ftp.write('RETR $file') or {
|
||||
}
|
||||
mut dtp := ftp.pasv() or { return error('Cannot stablish data connection') }
|
||||
ftp.write('RETR $file') ?
|
||||
code, _ := ftp.read() ?
|
||||
if code == denied {
|
||||
return error('Permission denied')
|
||||
|
Loading…
Reference in New Issue
Block a user