Is there any way to transfer files between computers using Python 3.6?

I want to transfer txt files between computers wihs are not on the same network.

1 answer

  • answered 2018-01-13 18:11 Simon

    Yes you can and if you know socket you could do it or use other libraries instead.

    You would need to create a script that works as a server (once again socket can do it, or you could use the inbuilt library http.server or anything that allows you to make a server).

    A simple server from the Python docs:

    import http.server
    import socketserver
    PORT = 8000
    Handler = http.server.SimpleHTTPRequestHandler
    with socketserver.TCPServer(("", PORT), Handler) as httpd:
        print("serving at port", PORT)

    Once your sever is working, you can add files to it to send you just need to receive it on the other pc this can be done effectively with urllib.request.

    Also you need to find your ip address.

    Here is a short demonstration on receiving information from a server:

    Although you need to find your ip in this example it's

    import urllib.request
    urllib.request.urlretrieve("", "filename.txt")

    Obviously this is not complete these are the steps you need to perform in order to do what you are asking. Once you have a basic system going then you could focus on including a GUI or making it possible to send files both ways (this would just involve a script that allows both to serve and to receive.