2019-12-28 11:41:54 +03:00
|
|
|
import net.ftp
|
2019-12-27 21:08:44 +03:00
|
|
|
|
2023-05-12 09:31:27 +03:00
|
|
|
fn test_ftp_client() {
|
2021-01-26 17:43:10 +03:00
|
|
|
$if !network ? {
|
|
|
|
return
|
|
|
|
}
|
2022-03-06 20:01:22 +03:00
|
|
|
// Note: this function makes network calls to external servers,
|
2021-01-26 17:43:10 +03:00
|
|
|
// that is why it is not a very good idea to run it in CI.
|
|
|
|
// If you want to run it manually, use:
|
2021-02-02 10:22:52 +03:00
|
|
|
// `v -d network vlib/net/ftp/ftp_test.v`
|
2021-03-01 02:18:14 +03:00
|
|
|
ftp_client_test_inside() or { panic(err) }
|
2021-01-26 17:43:10 +03:00
|
|
|
}
|
|
|
|
|
2022-10-16 09:28:57 +03:00
|
|
|
fn ftp_client_test_inside() ! {
|
2021-01-26 17:43:10 +03:00
|
|
|
mut zftp := ftp.new()
|
2021-02-02 10:22:52 +03:00
|
|
|
// eprintln(zftp)
|
2019-12-28 11:41:54 +03:00
|
|
|
defer {
|
2021-03-01 02:18:14 +03:00
|
|
|
zftp.close() or { panic(err) }
|
2019-12-28 11:41:54 +03:00
|
|
|
}
|
2022-10-16 09:28:57 +03:00
|
|
|
connect_result := zftp.connect('ftp.redhat.com')!
|
2020-11-15 23:54:47 +03:00
|
|
|
assert connect_result
|
2022-10-16 09:28:57 +03:00
|
|
|
login_result := zftp.login('ftp', 'ftp')!
|
2020-11-15 23:54:47 +03:00
|
|
|
assert login_result
|
2022-10-16 09:28:57 +03:00
|
|
|
pwd := zftp.pwd()!
|
2019-12-28 15:55:53 +03:00
|
|
|
assert pwd.len > 0
|
2021-01-26 17:43:10 +03:00
|
|
|
zftp.cd('/') or {
|
|
|
|
assert false
|
|
|
|
return
|
|
|
|
}
|
|
|
|
dir_list1 := zftp.dir() or {
|
2019-12-28 11:41:54 +03:00
|
|
|
assert false
|
|
|
|
return
|
|
|
|
}
|
|
|
|
assert dir_list1.len > 0
|
2021-01-26 17:43:10 +03:00
|
|
|
zftp.cd('/suse/linux/enterprise/11Server/en/SAT-TOOLS/SRPMS/') or {
|
|
|
|
assert false
|
|
|
|
return
|
|
|
|
}
|
|
|
|
dir_list2 := zftp.dir() or {
|
2019-12-28 11:41:54 +03:00
|
|
|
assert false
|
|
|
|
return
|
|
|
|
}
|
|
|
|
assert dir_list2.len > 0
|
2021-02-02 10:22:52 +03:00
|
|
|
assert dir_list2.contains('katello-host-tools-3.3.5-8.sles11_4sat.src.rpm')
|
2021-01-26 17:43:10 +03:00
|
|
|
blob := zftp.get('katello-host-tools-3.3.5-8.sles11_4sat.src.rpm') or {
|
2019-12-28 11:41:54 +03:00
|
|
|
assert false
|
|
|
|
return
|
2019-12-27 21:08:44 +03:00
|
|
|
}
|
2019-12-28 11:41:54 +03:00
|
|
|
assert blob.len > 0
|
2019-12-27 21:08:44 +03:00
|
|
|
}
|