##主要功能
Basic/Digest
authenticationFirst of all you should create client
instance using newClient()
function:
var client = webdav.newClient(
'http://localhost:6688/',
user: 'flyzero',
password: '123456',
debug: true,
);
// Set the public request headers
client.setHeaders({'accept-charset': 'utf-8'});
// Set the connection server timeout time in milliseconds.
client.setConnectTimeout(8000);
// Set send data timeout time in milliseconds.
client.setSendTimeout(8000);
// Set transfer data time in milliseconds.
client.setReceiveTimeout(8000);
// Test whether the service can connect
try {
await client.ping();
} catch (e) {
print('$e');
}
var list = await client.readDir('/');
list.forEach((f) {
print('${f.name} ${f.path}');
});
// can sub folder
var list2 = await client.readDir('/sub/sub/folder');
list2.forEach((f) {
print('${f.name} ${f.path}');
});
await client.mkdir('/新建文件夹');
// Recursively create folders
await client.mkdirAll('/new folder/new folder2');
If you remove the folder, some webdav services require a '/' at the end of the path.
// Delete folder
await client.remove('/new folder/new folder2/');
// Delete file
await client.remove('/new folder/新建文本文档.txt');
If you rename the folder, some webdav services require a '/' at the end of the path.
// Rename folder
await client.rename('/新建文件夹 /', '/新建文件夹 2/', true);
// Rename file
await client.rename('/新建文件夹 2/test.dart', '/新建文件夹 2/test2.dart', true);
If copied the folder (A > B), it will copy all the contents of folder A to folder B.
Some webdav services have been tested and found to delete the original contents of the B folder!!!
// Copy all the contents of folderA to folder B
await client.copy('/folder/folderA/', '/folder/folderB/', true);
// Copy file
await client.copy('/folder/aa.png', '/folder/bb.png', true);
// download bytes
await client.read('/folder/folder/openvpn.exe');
// download 2 local file
await client.read2File(
'/folder/vpn.exe', 'C:/Users/xxx/vpn2.exe');
// upload local file 2 remote file
await client.writeFromFile(
'C:/Users/xxx/vpn.exe', '/f/vpn2.exe');
CancelToken cancel = CancelToken();
// Supports most methods
client.mkdir('/新建文件夹', cancel)
.catchError((err) {
prints(err.toString());
});
// in other
cancel.cancel('reason')
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.