{"id":207800,"date":"2020-11-26T02:57:26","date_gmt":"2020-11-25T18:57:26","guid":{"rendered":"http:\/\/4563.org\/?p=207800"},"modified":"2020-11-26T02:57:26","modified_gmt":"2020-11-25T18:57:26","slug":"%e5%86%99%e4%ba%86%e4%b8%aa-webdav-%e5%ae%a2%e6%88%b7%e7%ab%af%e6%8f%92%e4%bb%b6%ef%bc%8c%e6%94%af%e6%8c%81%e5%b8%b8%e7%94%a8%e6%96%87%e4%bb%b6%e6%93%8d%e4%bd%9c","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=207800","title":{"rendered":"\u5199\u4e86\u4e2a webdav \u5ba2\u6237\u7aef\u63d2\u4ef6\uff0c\u652f\u6301\u5e38\u7528\u6587\u4ef6\u64cd\u4f5c"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u5199\u4e86\u4e2a webdav \u5ba2\u6237\u7aef\u63d2\u4ef6\uff0c\u652f\u6301\u5e38\u7528\u6587\u4ef6\u64cd\u4f5c               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : flyzero <\/span>  <span><i><\/i> 0<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<h1>webdav_client<\/h1>\n<p> <\/p>\n<ul>\n<li>https:\/\/pub.dev\/packages\/webdav_client<\/li>\n<li>\u4f7f\u7528 dio \u4f5c\u4e3a http \u7f51\u7edc\u8bf7\u6c42\u5e93\uff0c\u4e3b\u8981\u662f\u65b9\u4fbf\u540e\u7eed\u7684\u65ad\u70b9\u7eed\u4f20\u529f\u80fd\u6269\u5c55<\/li>\n<\/ul>\n<p>##\u4e3b\u8981\u529f\u80fd<\/p>\n<ul>\n<li>support <code>Basic\/Digest<\/code> authentication<\/li>\n<li>common settings<\/li>\n<li>read dir<\/li>\n<li>make dir<\/li>\n<li>delete<\/li>\n<li>rename<\/li>\n<li>copy<\/li>\n<li>download file<\/li>\n<li>upload file<\/li>\n<li>cancel request<\/li>\n<\/ul>\n<h2>Todo<\/h2>\n<ul>\n<li>Upload support for break uploads<\/li>\n<li>Download support for breakdowns<\/li>\n<\/ul>\n<h2>Usage<\/h2>\n<p>First of all you should create <code>client<\/code> instance using <code>newClient()<\/code> function:<\/p>\n<pre><code>var client = webdav.newClient(     'http:\/\/localhost:6688\/',     user: 'flyzero',     password: '123456',     debug: true,   ); <\/code><\/pre>\n<h3>Common settings<\/h3>\n<pre><code>    \/\/ 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');     } <\/code><\/pre>\n<h3>Read all files in a folder<\/h3>\n<pre><code>    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}');       });      <\/code><\/pre>\n<h3>Create folder<\/h3>\n<pre><code>    await client.mkdir('\/\u65b0\u5efa\u6587\u4ef6\u5939');      \/\/ Recursively create folders     await client.mkdirAll('\/new folder\/new folder2'); <\/code><\/pre>\n<h3>Remove a folder or file<\/h3>\n<blockquote>\n<p>If you remove the folder, some webdav services require a &#8216;\/&#8217; at the end of the path.<\/p>\n<\/blockquote>\n<pre><code>    \/\/ Delete folder     await client.remove('\/new folder\/new folder2\/');      \/\/ Delete file     await client.remove('\/new folder\/\u65b0\u5efa\u6587\u672c\u6587\u6863.txt'); <\/code><\/pre>\n<h3>Rename a folder or file<\/h3>\n<blockquote>\n<p>If you rename the folder, some webdav services require a &#8216;\/&#8217; at the end of the path.<\/p>\n<\/blockquote>\n<pre><code>    \/\/ Rename folder     await client.rename('\/\u65b0\u5efa\u6587\u4ef6\u5939 \/', '\/\u65b0\u5efa\u6587\u4ef6\u5939 2\/', true);      \/\/ Rename file     await client.rename('\/\u65b0\u5efa\u6587\u4ef6\u5939 2\/test.dart', '\/\u65b0\u5efa\u6587\u4ef6\u5939 2\/test2.dart', true); <\/code><\/pre>\n<h3>Copy a file \/ folder from A to B<\/h3>\n<blockquote>\n<p>If copied the folder (A &gt; B), it will copy all the contents of folder A to folder B.<\/p>\n<\/blockquote>\n<blockquote>\n<p>Some webdav services have been tested and found to delete the original contents of the B folder!!!<\/p>\n<\/blockquote>\n<pre><code>    \/\/ 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); <\/code><\/pre>\n<h3>Download file<\/h3>\n<pre><code>    \/\/ download bytes     await client.read('\/folder\/folder\/openvpn.exe');      \/\/ download 2 local file     await client.read2File(           '\/folder\/vpn.exe', 'C:\/Users\/xxx\/vpn2.exe'); <\/code><\/pre>\n<h3>Upload file<\/h3>\n<pre><code>    \/\/ upload local file 2 remote file     await client.writeFromFile(         'C:\/Users\/xxx\/vpn.exe', '\/f\/vpn2.exe'); <\/code><\/pre>\n<h3>Cancel request<\/h3>\n<pre><code>    CancelToken cancel = CancelToken();      \/\/ Supports most methods     client.mkdir('\/\u65b0\u5efa\u6587\u4ef6\u5939', cancel)     .catchError((err) {       prints(err.toString());     });      \/\/ in other     cancel.cancel('reason') <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>0<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u5199\u4e86\u4e2a webdav \u5ba2\u6237\u7aef\u63d2\u4ef6\uff0c&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/207800"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=207800"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/207800\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=207800"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=207800"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=207800"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}