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 开发者_如何学Gogiven 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.
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.
Use famous archiving methods (zip, rar...) and transfer data. The extract the at the peer side. This way you save:
- Implementing an error-prone recursive pattern.
- Your bandwidth
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.
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
精彩评论