-1

Ok i know i am asking a very basic question , but i have been going around net looking for a good tutorial but cannot seem to find one Can some one suggest a good tutorial on how to transfer files from client to server using TCP connection with python

Also if i want to transfer all the files in a directory including sub directories , what will be the best way to traverse directory and send each file one by one over the TCP Connection

Also the server end where it would read the file and store them in their respective directory in the root folder

A good Tutorial that can help me get started with TCP file transfer using Python would be great I am new to python

Hassan Jalil
  • 1,114
  • 4
  • 14
  • 34

1 Answers1

0

This question is a bit too vague or too broad for Stackoverflow, so expect downvotes or that your ticket gets closed. But I'd like to point out a roadmap of what you want to do.

Transferring a single file:

  1. Open a socket for listening on the receiver side.
  2. Connect to this listener from the sending side by opening a socket.
  3. Read the contents of the file chunkwise and write the chunks to the socket.
  4. On the receiving side read chunks from the socket and write them to disk into a file.
  5. When the end of the file is reached, close the sending socket.
  6. When the closing of the connection is detected by the receiver, close the file the chunks get written to.

Transferring multiple files (trees):

I'd propose to use existing tools like tar via the subprocess module to create a single stream out of an existing file tree or a list of files. Then transfer this stream in the manner described above. On the receiving side unpack the stream again via the subprocess module.

Alfe
  • 56,346
  • 20
  • 107
  • 159