Connect to remote server IP using Python and extract the files


I am trying to access a remote server using the IP and port number. After accessing Server I would like to read the files.

import socket

target_host = ""  # ip address or URL
target_port = xxxx

# create a socket object and handler
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as client:
    # connect the client
    client.connect((target_host, target_port))
    response = client.recv(4096)

This is usually a job for requests, or curl on the command line.

On the server, put the files you want to allow to be downloaded into their own special sub folder, and run an OpenSSH daemon, sftp service, or even just nginx (or upload them to a bucket and save yourself all the server admin).

There’s no need I’m aware of, to interact with your own server, or to legally interact with public servers, at the sockets level, just for file transfer.

Apart from what @JamesParrott wrote,
what protocol is the server running to provide access to the files?

Knowing the protocol will allow us to point you to existing library code to do the file transfers.