Ricky Robinson
Ricky Robinson

Reputation: 22903

Python: send file to a server without third-party libraries?

I have a Python client behind a NAT and a python server with a public IP address. My job is to send a pcap file (the size of a few MB) from the client to a server, as well as a dictionary with some data.

Is there any easy way of doing this without resorting to third-party libraries (e.g. twisted, tornado)? If not, what's the easiest alternative?

I thought I could send the pcap file through http so that it would be easier to read it on the server side, and perhaps I could do the same with the dictionary by first pickling it. Would it be a good solution?

(I have complete control on the server, where I can install whatever)

Upvotes: 2

Views: 871

Answers (3)

gbrennon
gbrennon

Reputation: 979

you can use just the classic sockets with TCP!

You just need to send the file via TCP sockets and receive it in a TCP socket server.

Read it as a file, send it and receive it.

This might give you some tip about sockets: https://docs.python.org/2/library/socket.html

Later I'll post a little script in case you didn't solve your doubt.

Upvotes: 0

Scott Hunter
Scott Hunter

Reputation: 49883

If you can install software on the server, and the server allows HTTP connections, you can write your own simple HTTP server (Python has libraries for doing that). If not, the answer would depend on what services are available on the server.

Upvotes: 1

Related Questions