Webdav protocol. Problem connecting via WebDAV

If, as an introduction, I began to describe the advantages of cloud data storage, you would think that I had just been defrosted after twenty years of suspended animation or that I was seriously abusing sleeping pills :). Therefore, I will say briefly, in programmer terms: when I was faced with the task of making a program that could work with files on multiple storages without being tied to the API of a specific service (we were talking about backup), it turned out that it was not so simple. I decided to tell you about all the subtleties and pitfalls of the work done in this article.

WebDAV

WebDAV (Web Distributed Authoring and Versioning) is a protocol for transferring and working with data, built on top of HTTP 1.1. It should be noted here that the transmission can be either secure or unsecured. There is no security in the protocol itself, but it can be added through the implementation of authentication on the web server and encryption via SSL, therefore, in this case, HTTPS will be used instead of HTTP.

DAV was originally developed for collaborative creation and editing of web pages, but in the process of use it found application as a network distributed file system, effective for working in a high-load environment and supporting unstable connections. Thus, DAV is suitable for managing files on web servers, in other words, implementing cloud information storage, where it was used. With its help, you can perform basic operations on files contained on the server, carry out advanced operations, such as: blocking, obtaining metadata, version control and others. This protocol became a replacement for the good old FTP, whose time has come to an end.

WebDAV provides seven commands:

  • PROPFIND - getting the properties of an object on the server in XML format;
  • PROPPATCH - changing object properties;
  • MKCOL - create a folder on the server;
  • COPY - copying on the server side;
  • MOVE - moving on the server side;
  • LOCK - lock an object;
  • UNLOCK - remove lock from an object.

Thus, WebDAV allows you to change the properties of objects stored on the server, perform a search based on properties, lock an object (in our case, a file) so that only one user can edit it in a distributed environment in which many users can have access, manage file versions (via legacy check -in, -out commands), as well as perform advanced list-based file access control.

In addition, WebDAV supports legacy commands: GET - to download a file, PUT - to upload to the server, and DELETE - to delete an object. We won't look at all commands; in my case, to implement the functionality of the utility, I needed only four.

Currently, Microsoft, Mozilla, Novell, IBM and others are involved in the development of the protocol. Therefore, it should not be surprising that WebDAV support is present in many Microsoft products (including Internet Explorer, Explorer, IIS web server and others), Mozilla browser Firefox, Novell, IBM products. Additionally, by installing plugins you can “make friends” with the protocol Total Commander and FAR.

As already mentioned, on Windows remote storage WebDAV can be connected to Explorer as additional disk. You can do the same in OS X by organizing the connection to the WebDAV server as an additional directory in the Finder browser.

Possible solutions

I was faced with the task of connecting and organizing work with data on two file storages: Yandex.Disk and Dropbox. Both of these services support the WebDAV protocol. By registering your mail on Yandex, you automatically get access to 10 GB of cloud storage, which you can connect to not only through standard client, but also using a third-party tool (for example, your own program) via the WebDAV protocol. When you register for Dropbox you get 5 GB disk space, which can be used through a standard client. However, to access the storage via WebDAV, you must go through additional registration. As a result, as it turned out, this access is not free, however, after registration it is given free access for two weeks. The storage sizes can be increased: either through an additional payment, or by participating in various promotions carried out by services, for example, finding bugs and reporting them to developers.

When I needed to write a program to work with the WebDAV protocol, the first thing I did was look at the Win32 API to see if there were functions for this, similar to those available for working with FTP. Looking ahead, I’ll note that I had a tight deadline, so use the functions API level I didn't mean to. As you would expect, in the Win32 API, starting with the version for Windows Vista, includes WebDAV API. It includes one enumeration, three structures and a set of functions. I thought it was good sign, because there are certainly higher-level solutions based on the standard API and I won’t have to linger with the API functions.

Then Delphi XE3 came to hand, and I decided to check what tools it had for working with the WebDAV protocol. It turned out that it (on the Indy Clients tab of the component palette) contains the IdWebDav component. I already thought that this was the end of the research... But it turned out that this component does not connect to Yandex in any way (Yandex.Disk was a higher priority service for me, so I primarily carried out all the tests on it).

Then I decided to use the old, but time-tested network library Synapse for Delphi. In addition, there is an excellent site on the RuNet containing several articles dedicated to this library, www.webdelphi.ru. At first, the work went well, and I was able to implement several functions of the protocol: creating a folder, downloading files, getting object properties. But the most important function - uploading files to the server from a local computer - was never implemented. It became sad: there is no sensible information about this protocol on the Internet. Bing found several paid sets of components for working with the network, one of which, out of curiosity, I decided to use to find out whether it was possible to upload a file to Yandex.Disk. This one turned out to be Clever Internet Suite. Having created a component of the clWebDav class, we managed to upload a file to the server with one line of code:

where stream is a file stream previously created for reading.

Great, but the cost of this product is off-putting: more than $500. that is, what is not gud. If you want to use this method, then pay attention to the version of the library: you can connect to Yandex only using version 7.0 and higher; if you use version 6.0, which is widespread on the Internet, then uploading data to the server will not be possible. I got tired of playing around with Delphi and decided to turn to dotNET and C#.

Connect to Yandex.disk + create a collection

Since WebDAV runs on top of HTTP/S, I decided to use the HttpWebRequest and HttpWebResponse classes, which have been included in the .NET Framework since version 2.0. In this case, we will use the .NET Framework 4.0 - I’ll tell you why below. In short, the first of the listed classes represents an HTTP request, the second represents an HTTP response. Our task is to correctly formulate the request so that the WebDAV server can understand it. To find out how to correctly formulate requests to the WebDAV server, please refer to the Yandex documentation on using the WebDAV protocol.

Next action Let's write a small program that can perform four operations: create a folder on a remote host, upload an object, download an object, and delete an object. These operations are sufficient for most applications that solve production tasks. For simplicity, let's create a WinForms application. In a few words I’ll tell you about my program. It is a console application launched by a batch file on a schedule. Its main action is uploading files to a remote host, while its tasks include correct processing of the mask for selecting files, as well as processing the paths on which they are located, plus correct creation in the cloud, a folder hierarchy similar to that hosted on local disk. Moreover, since the program runs in automatic mode, it creates a log file. In today's program we will skip these steps (obviously they are off topic) and focus on the WebDAV protocol.

Please note: when creating a project template, it is better to use .NET Framework 4.0 as a basis. And although support for WebDAV appeared in the second version, tests showed that the same program, recompiled using .NET 4, works twice as fast, and this concerns the speed of working with files and sending them.

After creating the application template, place four buttons on its form. The first operation we will implement will be creating a folder (or collection). She is the simplest of all. Note: although Yandex.Disk works over a secure HTTP protocol S, the folder can be created via HTTP. We will also need four input fields on the form: to specify the address of the remote host (for now we will aim at Yandex.Disk: https://webdav.yandex.ru/), to enter the username, password (for authentication on Yandex) and to enter the folder name , which we want to create in the cloud (Fig. 1). Please note: the server address must be entered together with the protocol, in in this case https://.

First of all, include namespaces in your code: using System.Net; - for working with the network and using System.IO; - for file I/O. Then create a handler for the click event on the CreateDir button. Write the following code in it:

String folder = folderEdit.Text; String url = urlEdit.Text; String userName = nameEdit.Text; String password = passwordEdit.Text; url += folder; url = url.TrimEnd(); HttpWebRequest request = HttpWebRequest.Create(url) as HttpWebRequest; request.Credentials = new NetworkCredential(userName, password); request.Method = WebRequestMethods.Http.MkCol; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); HttpStatusCode code = response.StatusCode;

Let's discuss the code briefly. At the beginning, for convenience, we place the data from the input fields into variables: folder name, host address, user name and password. Next, we form the URL: add the name to the host address folder being created. Like HTTP, WebDAV has standard room port is 443, so it is not necessary to specify it. Now, based on the URL, we can create an HTTP request object, which is done in the next line. After creation, you need to fill in some of its properties. That is, it is necessary to specify the data that will be sent to the server in the request header. Let's look at the Yandex documentation (link given above). Required parameters include authentication information. Yandex accepts this data in two forms: Basic - login and password, QAuth - token using the QAuth protocol. We will choose the first path. However, in this case the data must be encoded. This is done by an object of the NetworkCredential class, whose constructor receives the name and password as strings. The created object of this class is assigned to the Credentials property of the request object. Next line we tell what command we want to execute - MKCOL. In this case, no data is required to be transmitted/received, and immediately after this we send the request. Next, we can see what response the server returned; if successful, the response will be the Created string. The HttpWebRequest class defines many responses to all cases of joint communication between the client and server.

The WebDAV protocol does not allow creating several subfolders in one request, for example /folder1/folder2/; You can create only one folder: /folder1/. If the directory exists and the sent request tries to create a directory of the same name, then the server will generate an exception that must be caught with a try/catch construct. The example above does not handle exceptions, so if you use this code in your application, do not forget to add it. If you need to find out whether a directory exists or not, then you can use the PROPFIND request, and then receive and parse the server response containing information in XML format about the objects available on the server. But this will take a long time, and, in my opinion, it is better to use the MKCOL request and, if a folder of the same name is present, handle the exception. Thus, in his console utility I'm creating a folder hierarchy. In addition, if a directory of the same name already exists, it is entered.

Deleting an object

Deleting a file and/or directory using the WebDAV protocol is as simple as creating a collection. To implement this task, use the above code, in which you need to replace the line specifying the method executed by the server with the following:

Request.Method = "DELETE";

As you can see, the WebRequestMethods.Http class does not have a Delete method, but we can specify the desired method as a string. It will be sent to the server, the main thing is that it is able to process and execute this method, and the WebDAV server, as we know, is capable of this.

In this case, it is also better to use the try/catch construct to catch the exception that may occur due to the absence of the object to be deleted.

Downloading a file

To download a file from a cloud storage using the WebDAV protocol, you do not need to do much manipulation with the existing code. But first, upload a file to the cloud using standard means (via the web interface or desktop Yandex client). According to the plan, when downloading a file, in the fourth (lower) input field we will enter the name of the file that we want to download. We will assign the same name to the result file on the local computer. Note that on the server we can specify /Software/file.txt and the file in the Software folder will be accessed, but in the local file system The folder will not be created automatically, so you must first create it. In short, we will download the ZuneSetupPkg.exe file (an indispensable tool for working with Windows Phone, which I often have to reinstall on other people’s computers, so I always have it at hand - in the cloud) from the root of Yandex.Disk to the directory with the executable file.

In the handler for clicking on the Download button, after initializing the variables, creating a request object and setting Credentials, set the method type: GET (see the source in the materials for the number). Then, having received the server response (an HttpWebResponse class object), we declare variables for reading data:

Int byteTransferRate = 8192; // Buffer size byte bytes = new byte; // Buffer int bytesRead = 0; long totalBytesRead = 0; long contentLength = long.Parse(response.GetResponseHeader("Content-Length"));

In the last line of code, we read the file size from the response header from the server and save it to a variable. Next, we create a file stream to write a file to disk:

FileStream fs = new FileStream(fileToDownload, FileMode.Create, FileAccess.Write);

Then we receive the stream from the server:

Stream s = response.GetResponseStream();

We read data from it in portions and write it to a file until there is something to write:

Do ( bytesRead = s.Read(bytes, 0, bytes.Length); if (bytesRead > 0) ( totalBytesRead += bytesRead; fs.Write(bytes, 0, bytesRead); ) ) while (bytesRead > 0);

After all the data has been written to the file, close both streams and the server response. While reading data, we increased the totalBytesRead variable by the number of bytes read. In this case, if there are no errors, the size of this variable should become equal to the size that we calculated from the header, and if this is so, then the file was downloaded correctly and we display a message about this (Fig. 2), but if the sizes are not equal, then a failure occurred , we also inform the user about this.

This code is not without exceptions that need to be caught, among them: (404) the file cannot be found (on the server), it is impossible to write to the specified location, and many others.

Uploading a file to the server

The last operation, without which our utility will be incomplete, is uploading the file to the remote host. This is the most “cunning” operation. The operations discussed above did not cause the slightest difficulty, but this one turned out to be cooler! I have already said that there were difficulties with the implementation of file loading when using other development tools. And not everything was smooth in C#. First, in the documentation, we’ll look at what request Yandex is waiting for to upload a file (Fig. 3).

In a full-fledged program, it is necessary to upload several files at once (at the user’s request), select files by mask, create a directory hierarchy, and, finally, handle errors. We, in order not to pound water in a mortar, will omit all this and concentrate on loading one given file, without creating folders and handling errors. We'll leave all this to you as homework. So, in the program I prepared, the UpdateFile method is called from the button click handler, the host name and the name of the downloaded file, which are taken from the corresponding input fields, are passed to it. The beginning of the method itself is similar to those discussed above, but now in the request header we send the PUT command to be executed by the server, that is, we express our desire to download the file. If when performing previous requests we did not particularly rely on the documentation, then this time it will be very useful to us: we will include in the request header all the fields recommended by Yandex, as well as some additional ones. So, let's look at the header code, and then discuss the problems:

Request.ContentLength = fileLength; request.KeepAlive = false; request.ReadWriteTimeout = -1; request.Timeout = -1; request.AllowWriteStreamBuffering = false; request.PreAuthenticate = true; request.SendChunked = false; request.ContentType = "application/binary"; request.ProtocolVersion = HttpVersion.Version11; request.ServicePoint.ConnectionLimit = 1; request.AllowAutoRedirect = false; //request.Expect = "100-continue"; request.ServicePoint.Expect100Continue = true; request.Accept = "*/*";

The values ​​of some parameters are derived by scientific poking. Some properties depend on others. So, it is better to disable the persistent connection (second line), because this will generate an exception about the impossibility of simultaneous reading and writing to the stream. The next two properties set the timeout for reading and writing to the network stream. A value of -1 means infinity. The size of the downloaded file may be indefinitely large, so we cannot predict the time it will take to download it. The next property: AllowWriteStreamBuffering is very interesting, it enables or disables buffering of data before sending. When enabled, the sent file is first loaded into memory, and only then uploaded to the server. The strangeness of this property is that on some hosts you can upload a file without problems by disabling buffering, but on others an exception will pop up about the need for buffering. This may be due to some registry or communication settings; I also don’t rule out differences between services. If buffering is enabled and is sent to the server big file, may be out of resources (SystemOutOfMemory exception). You can add a checkbox to your program to enable or disable buffering. If buffering is disabled, then the PreAuthenticate flag (the next property) must be enabled, which sends authentication data along with the header. Next parameter SendChunked (only for Yandex.Disk) allows you to upload files of a predetermined size to a remote host, to which Dropbox responds with an exception. Next, we indicate the type of data being transferred, the version of the protocol used (11 means 1.1), and the number of possible HTTP connections: there is no need for more than one. We prohibit automatic redirection. To set the following recommended field: “Expect: 100-continue”, which includes waiting for a response for a download request, you cannot use the commented out property, you must use the code in the line below: request.ServicePoint.Expect100Continue = true;. The last property of the HTTP header includes a mask for the received objects; in our case, any files are accepted: with an arbitrary name and extension.

After the request is formed, we need to receive a network stream in which we will record the data sent to the server. We also open local file for reading. We allocate a byte buffer for temporary storage of data read from the file; then in a loop we begin to read and send, writing data to the stream. After this, close the network and file streams, in general, as usual. Having received a response from the server, we check the HTTP status to see if it is equal to the Created flag and compare the file size with the number of bytes transferred; if both conditions are met, then the transfer is successful, otherwise there is a problem.

Results

This concludes the development of our utility. In it we have implemented all the planned functionality - the four most necessary commands, without which no file management manager on a remote host can do. We did not become tied to the services of a specific hosting; using its API, we developed universal application, communicating with the server using the standard WebDAV protocol. This allowed our program, using one code, to connect to several servers at once (I tested on Yandex.disk and Dropbox). However, as we have seen, different services interpret and support the protocol slightly differently.

I leave the further development of the program to you; during the course of the article I pointed out possible improvements: this includes loading several files, creating a hierarchy of folders, parallelizing loading, and much more. If you dig deeper into the WebDAV protocol, you can implement other commands to manage content on the server.

On this note, I want to wish you good luck in all your endeavors and be more... fresh air:). See you on the pages of ][!

In this article we will look at the WebDAV protocol, which allows you to work with files on remote data storage servers like Yandex.Disk. First of all, this is relevant for Linux users, for which such services are not always made by special clients. But the arguments in favor of WebDAV may also be of interest to users of other operating systems.


Universal Access to the "clouds"

Last week I got more “cloud flash drives”. In addition to Ubuntu One and Dropbox sent their invites and services Google Drive and "Yandex.Disk". In total, I already have four “cloud drives”.

And this is not the limit. Similar " cloud services" are becoming popular, and there are also, for example, SugarSync, Box and others. On the one hand, such variety and choice is all good for end user. But, on the other hand, questions arise with working with a large number similar services, when there is not one, but several of them.

After all, each service tries to release its own client to integrate itself into the user’s system. And when there are a lot of such “flash drives”, then the abundance of such clients is unlikely to be aesthetically pleasing. And, for example, for Linux, on the contrary, there may not be a special client at all.

Hence the simple conclusion that I would like to have some universal method integration of “cloud flash drives” into the system, without the need to install its own program for each service.

And this method may well be the WebDAV protocol. This protocol allows you to work with files on a remote server and perform normal actions with them: reading, writing, deleting.

Support for this protocol is available in many operating systems - Linux, Windows, Mac OS. Another thing is that not all cloud services provide access via WebDAV. But honor and praise to Yandex.Disk, which not only provided support, but also encourages the use of the WebDAV protocol. Therefore, let’s take a closer look at this protocol.


What is WebDAV

WebDAV (Web-based Distributed Authoring and Versioning) is an extension of the HTTP protocol that allows you not only to load web pages into the browser, but also, using an expanded set of commands, to work with files on a remote server, and not only with files. That is, WebDAV is a replacement for the FTP and SMB protocols.

The protocol also allows you to perform advanced types of operations - blocking, version support, and working with object metadata. It is also possible to work not only with files, but also with other objects, for example, address book entries.


WebDAV and Linux

As mentioned above, WebDAV is primarily relevant for Linux users. And support for the WebDAV protocol in Linux has been introduced a long time ago. This support can be provided both at the level of individual file managers and at a deeper system level using special packages.

First, let's look at how to connect a WebDAV resource in standard file manager"Nautilus". Let's look at the example of connecting to Yandex.Disk.

File GNOME manager has built-in support for WebDAV, so its users do not need to install anything. You should open the "File - Connect to server" window and enter the following data here:

Server: webdav.yandex.ru
Type: Secure WebDAV (HTTPS)
Username: your login on the service
Password: password for the service

After which “Nautilus” will connect to the “cloud flash drive” and create a bookmark in the sidebar along with other sections. In reality, the resources mounted by Nautilus are located in the ~/.gvfs directory.

There is also a more classic and universal way of mounting “cloud flash drives” into the system.

First, install the davfs2 package, designed to work with WebDAV:

Sudo apt-get install davfs2

We create a directory in the home directory for mounting the “cloud disk”, and for example, let’s call this directory cloud:

$ mkdir /home/home/cloud

The davfs2 utility has special file configuration in which you can save your login and password so that you don’t have to enter them every time you mount a cloud disk. To do this, write a special line in the /etc/davfs2/secrets file with your username and password for the Yandex service:

Https://webdav.yandex.ru:443 login password

Https://webdav.yandex.ru:443 /home/home_directory/cloud davfs uid=user,file_mode=640,dir_mode=755,user,noauto 0 0

Then we add ourselves to the davfs2 group:

$ sudo usermod -a -G davfs2 user

To allow mount.davfs to run ordinary user let's run the command:

$ sudo chmod 4755 /usr/sbin/mount.davfs

That's it, now it's ours" cloud drive" on Yandex can be mounted with a simple command:

$ mount /home/home/cloud

And unmount:

$ umount /home/home/cloud

Mikhail ASTAPCHIK

Cloud storage Yandex Disk can be connected to your computer as network drive, via WebDAV protocol. After connecting a network drive, you will be able to work with Yandex cloud storage from your computer, as with a regular drive in operating system Windows.

In Yandex.Disk, you can store your files in the cloud, interacting with the storage using special program-client, or managing your data through the web interface using a browser.

When using a special program from Yandex, your files will be stored simultaneously on your computer and in cloud storage, and when using the web interface, your data will be stored only in cloud storage.

You can also use Yandex.Disk as a network drive. This will allow you to access your cloud storage files directly in File Explorer. The Drive will be connected to the computer using the WebDAV protocol.

WebDAV (Web-based Distributed Authoring and Versioning) - translates something like this: web tools for distributed development and version control. It is a set of extensions that sit on top of the HTTP protocol that allow users to collaboratively edit and manage files on a remote web server.

After connecting Yandex.Disk as a network drive to your computer, you will have access to all the contents of the cloud storage in this account. In this case, connected using WebDAV, will be available only when the Internet connection is connected. If Internet access is disabled, then in this case, access to the network drive will be terminated.

Another feature of using Yandex.Disk using the WebDAV protocol is that all the data in this cloud storage will be located in the cloud and not on your computer. You work with cloud storage like a regular disk on your computer, and all data will be physically located on remote server Yandex.

If you already have a client program installed on your computer and you use cloud storage on your computer, then when you connect Yandex.Disk via WebDAV, you can additionally connect to your computer a network drive with your other Yandex cloud storage.

You may have several cloud storages in Yandex. This is a fairly common occurrence, since many users may have several email accounts in Yandex. Yandex.Disk is linked to the email mailbox, so these users will automatically have multiple cloud storage options that they can use.

How to connect Yandex.Disk as a network drive to a Windows computer

To connect a network drive in the operating room Windows system, you will need to click first right click from the “Computer” or “This Computer” icon on the Desktop or from the “Start” menu. Then you will need to select the context menu item “Map network drive...”.

You can connect a network drive differently from the Explorer window opened in the “Computer” tab. There you will need to select “Map network drive”.

Next, the “Map network drive” window will open. In this window you can select a letter for the new network drive. By default, Windows automatically selects an available letter of the alphabet. You can change the drive letter if you need to.

In the “Folder” field you will need to enter the following address:

https://webdav.yandex.ru

By default, the “Restore at login” option will be activated.

After completing the settings selection, click on the “Done” button.

After successfully connecting the network drive, the “Windows Security” window will open.

Here, in the “User” field, you will need to enter the login for your Yandex.Disk account. Since the login is tied to a mailbox in Yandex, please note that in this case, you will need to enter an incomplete address email, but only the login (what comes before the “dog”).

In the "Password" field, enter the password for your account. Then, activate the “Remember credentials” option so as not to re-enter your data every time you connect to a network drive. Next, click on the “OK” button.

After this, the Explorer window will open cloud storage Yandex.Disk. All files and folders that are located in this particular cloud storage will be displayed here.

In the Explorer window, all network drives connected to your computer will be displayed in the “Network Location” area.

Now you can use the Yandex cloud as a regular disk on your computer.

How to disconnect a network drive Yandex WebDAV

To disconnect webdav yandex disk from your computer, first you will need to click on the “Computer” or “This computer” icon, and then on context menu You should select “Disconnect network drive...”.

In the window that opens " network drives", you will need to highlight required disk, and then click on the “OK” button.

After this, the Yandex.Disk network drive will be disconnected from your computer.

Conclusions of the article

You can connect the Yandex.Disk cloud storage to your computer as a network drive using the WebDAV protocol. In this case, you will use the cloud as a network drive. At the same time, your files will be physically located on a remote server, and you will be able to work with them as if regular disk your computer.


Compared to FTP, the WebDAV protocol has several advantages:

  • Performing basic file operations over objects on a remote server;
  • Perform advanced file operations (locking, version support);
  • Work with any type of objects (not just files);
  • Support for metadata (properties) of objects;
  • Support simultaneous work over objects.
  • No need to open additional ports (works over http).

Before we begin, we need to access the contents of which using WebDAV.

Setting up IIS + WebDAV

This example uses IIS 7.5, which is included with Windows 7.

Open Control Panel -> Programs -> Turn it on or off Windows components. In the list, expand “IIS Services” -> Internet Services -> General Features HTTP -> mark the “WebDAV Publishing” component:

Next, open the “IIS Services Manager” (Start -> Right click on Computer -> in the menu select Management -> Services and Applications). Select a site, in my case it is Default Web Site (default website). Go to the “Authentication” section. Here you need to make sure that Windows Authentication is enabled:

Open the “WebDAV Development Rules” section.

Add a new development rule. Allow access - to all content. Next, we indicate the user group that is allowed access. In my case this is the Administrators group. At the bottom in the “permissions” section, check all three options (read, source, write) to ensure full access:

The last step is to enable WebDAV (in the right column there is a link “Enable WebDAV”):

Just in case, restart IIS. That's all. Now let's try to connect.

Let me remind you once again that for WebDAV to work, you do not need to open any additional ports, except, of course, TCP 80. That is. if you have access to the site, then WebDAV will work.

Connection

The fastest and easiest way: on the command line, run

net use * http://ip_address_of_site/

Or through a graphical interface. Open Start -> Computer -> Map network drive. Enter the server address (required from http://) and click Finish.

Enter your username and password:

After clicking OK, a window with the contents of the remote server will open.

Tablet computer iPad convenient for using the Internet and working with documents on business trips, trips, and just anywhere. iWork programs can import files previously saved in /Documents, or download them from a WebDAV server or from MobileMe (which, strictly speaking, is also accessed via WebDAV). At the same time, MobileMe is significantly inferior to Dropbox in terms of synchronization capabilities, and does not work on Linux and Android. In addition, Pages, Keynote and Numbers do not support Dropbox, which is simply an exemplary cloud synchronization server.

The solution is to make a directory accessible via WebDAV and synchronized with Dropbox. I have a “black box” at home – a Netgear ReadyNAS file server on Linux. This is where everything will work.

There are two difficulties in the whole story: a dynamic external IP address and synchronization with Dropbox.
The first is solved by registering with DynDNS and setting up the router for automatic notification DynDNS about changing IP. Many modern routers have this feature. If it is not there, you need to install the DynDNS client on some constantly running computer in home network, for example, on a file server.
On dyndns.org you can borrow a domain name for free, which will allow you to connect to your server from anywhere in the world, without worrying about the IP address. In addition to the DNS service itself, the service provides information on your IP address and the history of its changes.

For the WebDAV server to work correctly, you will need to configure port forwarding on your router. Then the router will redirect the request received to your IP address to the specified computer from internal network. Therefore, it is important to specify a static internal IP address in the DHCP server rules on the router for the computer on which the WebDAV server is running. Static IP address specified by the corresponding MAC address of the network adapter.

Now let's set up Port Forwarding. Everyone knows that the HTTP protocol corresponds to port 80, SSH – 22, HTTPS – 443. For WebDAV, we just need 443/HTTPS. In the NAT tab of your router settings, specify rules for ports 443, 22 and, preferably, 80.

Most likely, you will also have to open external access to the services of your internal network so that you can freely access the WebDAV server.

You may need SSH for remote control the internals of the server, and it’s simply a sin not to use HTTP. If you are not going to host your site on a server at home, then it is advisable to at least put a “stub” so as not to tease those interested open page router settings.

Many modem routers do not have the NAT Loopback function (dlink.ru/ru/faq/160/139.html), so from the inside you will not be able to see what your service looks like from the Internet. You can only make sure that everything works from another computer in another location, or from a smartphone via 3G.

Half the work is done, all that remains is to install the WebDAV server on your computer or file server, and set up synchronization with Dropbox. Netgear NAS devices include, among other things, the ability to access network resources via WebDAV. In general, I must say that Netgear is very good in this regard: high speed access via Gigabit LAN, many functions that you may need, a bunch of access protocols and normal Linux on board.

Open the NAS settings page, enable access via the WebDAV protocol to the desired folders:

In addition, connect the file directory for the web server, which runs over HTTP, so that http://yourname.dyndns.org does not display a list shared resources, and your site or stub page:

Now everything should work: external access via WebDAV, SSH and HTTP to your resources.

If you want to add the ability to synchronize with Dropbox to what has already been done, you will need to install the Dropbox service on the system. In my case, I have to tinker with this by connecting over the network via SSH, since the NAS server does not have a monitor with graphical interface. If Dropbox is already running on your device, install it as a different user. The website has detailed instructions on how to do this: http://wiki.dropbox.com/TipsAndTricks/TextBasedLinuxInstall
After dropbox installations will display a link that needs to be activated on the site, after which synchronization will begin. To successfully solve our problem, you need to make a symbolic link that will connect the Dropbox folder with a directory accessible via WebDAV, or immediately install the unpack .tar.gz archive with Dropbox in the parent folder containing the shared resource:

On the ReadyNAS, shared directories are stored in /c/, and the archive with the dropbox service must be unpacked into the same directory.

On the tablet (which is why everything was started), when importing documents from the Internet, you need to specify the server address (and folder), as well as a name and password:

Server address: https://yourname.dyndns.org
Username, password: Your credentials on the NAS

After successful authentication, the program will display a list of folders from which you can import data and where you can save documents.

Of course, on Mac OS and Windows you can also connect to network folder for reading and writing. However, in Windows Vista and Windows 7, WebDAV works, to put it mildly, through one place; connecting through Explorer will not work. But everything works through the command line:

net use * https://yourname.dyndns.org/yourdirectory