Raphael
Raphael

Reputation: 592

How to send folders in c# through TCP?

I'm having trouble looking for a way to send whole folders over TCP. My initial idea was that the sender sends a string that contains the path of a given file like C://MyFolder/MySubFolder/MyFile then the receiver creates the folders and subfolders. The sender then goes ahead with the sending of the files containing their directory.

I think it goes without saying that this is not the best method in doing this. Is there a better approach?

EDIT:

Sorry if I was a little vague. I have a file transfer app that sends sends/receives files obviously and I want to add a way to send whole folders.

Upvotes: 1

Views: 2177

Answers (4)

FinalNotriX
FinalNotriX

Reputation: 395

If you consider zipping/compressing: You could have a look at GZipStream class for that.

http://www.geekpedia.com/tutorial190_Zipping-files-using-GZipStream.html

Upvotes: 0

Teoman Soygul
Teoman Soygul

Reputation: 25742

You need some sort of a file transfer protocol for that (i.e. FTP). Use an easy to setup c# FTP server library (i.e. this one: http://sourceforge.net/projects/csftpserver/) on the sending side and use FtpWebRequest on the client side to get the whole folder structure.

Upvotes: 2

Michael Stum
Michael Stum

Reputation: 180954

Have you looked at existing protocols for this purpose? It seems you want to clone FTP, maybe with a streaming mechanism like tar in between.

Upvotes: 1

Xaqron
Xaqron

Reputation: 30857

Use famous archiving methods (zip, rar...) and transfer data. The extract the at the peer side. This way you save:

  1. Implementing an error-prone recursive pattern.
  2. Your bandwidth

Upvotes: 1

Related Questions