Python network file server




















Well, if the server has two IP addresses, let's say " Alternatively, you can use either your public or private IP address, depending on your clients. Also, Make sure you use the same port in the server as in the client.

Let's create our TCP socket:. After that, we gonna listen for connections:. Once the client connects to our server, we need to accept that connection:. Remember that when the client is connected, it'll send the name and size of the file, let's receive them:. After that, we need to remove the absolute path of the file, that's because the sender sent the file with his own file path, which may differ from ours, the os.

Now we need to receive the file:. Not quite different from the client code. Once that's finished, we close both the client and server sockets. To create a socket, you must use the socket.

Once you have socket object, then you can use required functions to create your client or server program. To write Internet servers, we use the socket function available in socket module to create a socket object. A socket object is then used to call other functions to setup a socket server. Now call bind hostname, port function to specify a port for your service on the given host. Next, call the accept method of the returned object.

This method waits until a client connects to the port you specified, and then returns a connection object that represents the connection to that client. Let us write a very simple client program which opens a connection to a given port and given host. This is very simple to create a socket client using Python's socket module function. The socket. I have the username and password to the shared folder.

What would be the code? Add a comment. Active Oldest Votes. DavidJ 3, 4 4 gold badges 23 23 silver badges 39 39 bronze badges. Johnsyweb Johnsyweb k 23 23 gold badges silver badges bronze badges.

This just solved a problem that was annoying me, thanks! This only works on Windows yes, the question is tagged Windows, but accessing a Windows server from non-Windows OS may also be tagged as such. Anyone care to add a solution for other platforms e. Linux - if possible without something like Samba?

DavidJ Did you try Johnsyweb solution? Did it work? Johnsyweb have you got another solution for this somewhere? Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics. Next Python Pandas dataframe. Recommended Articles. Article Contributed By :. Easy Normal Medium Hard Expert. Writing code in comment?



0コメント

  • 1000 / 1000