File Sharing using HTTP (Python and go language example)

Source: Internet
Author: User

File Sharing is indispensable in normal work, so it is necessary to understand the file sharing method.

There are many methods for file sharing, which are roughly divided into the following categories:

1,System sharing (WindowsShared orSambaAnd so on):

WindowsNext we can useWindowsSharing to complete simple file sharing,LinuxYou can also useSambaAnd other software.

2,FTPShare:

CommonFTPSoftware Implementation.

3,HTTPShare:

CommonWebServer(For exampleIIS,ApacheAnd so on)Implementation.

What I want to introduce today isHTTPFile Sharing.

FirstIISFor exampleWebThe method for implementing file sharing on the server is as follows (take my machine as an example ):

1OpenIIS, Open the "website-->
Default website, right-click "properties", and click"Main directory",Select "directory browsing,As shown in: 

2, Enter the folderC: \ Inetpub \ wwwroot, Copy the file"1.7z"To this directory:

3, Open the browser, enter the Local MachineIP(For example, my:192.168.1.123) To view the shared file and download it:

Click"1.7z"To download.

Here I have implemented file sharing, but if I do notIISOrApacheAnd so on.WebHow to Implement server softwareHTTPWhat about file sharing?

Write a file for sharing.ProgramBai!

Don't be scared.PythonOrGoLanguages can be easily implemented:

1,PythonImplementationHTTPFile Sharing:

UsedPythonAll knowPythonThere is a very good guyXCommand:

Python
-M simplehttpserver 

InC: \ python27Run the following command:

Open your browser and you will see the following results:

The default port for this command is8000If I add a port parameter, you can use another port for access. The command is as follows:

Open your browser:

You can writeBatFile.CopyDouble-click the corresponding directory, for example, myHttpshare. batThe file is as follows:

Python-M simplehttpserver 80

Default80Port.IPAddress.

2,GoLanguage implementationHTTPFile Sharing:

The above method is very convenient,WindowsAndLinuxYou can only installPython

Here I have a usageGoLanguage implementation is alsoWindowsAndLinuxEat all (WindowsIf you do not know how to configure it, refer to my previousArticle:Http://www.cnblogs.com/MikeZhang/archive/2012/02/09/windowsGo.html
), SimilarC/C ++, YesCodePortable. You only need to compile it once before use.

The following is the sample code (Httpshare. Go):

 package main 
Import (
" HTTP "
" FMT "
)
func main () {
H: = http. fileserver (HTTP. dir ( " . ")
var port string
FMT. printf ( " Please input port number: ")
FMT. scanf ( " % S " , & Port)
HTTP. listenandserve ( " : " + port, h)
}

Running effect:

The technology serves our daily lives. If you think that is simple, you can use the above methods to share files.

Okay, that's all. I hope it will help you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.