如何通过TCP在C#中发送文件夹?
我在寻找通过 TCP 发送整个文件夹的方法时遇到困难。我最初的想法是发送者发送一个包含给定文件路径的字符串,例如 C://MyFolder/MySubFolder/MyFile,然后接收者创建文件夹和子文件夹。然后,发送者继续发送包含其目录的文件。
我认为不言而喻,这不是最好的方法。有更好的方法吗?
编辑:
抱歉,如果我有点含糊的话。我有一个文件传输应用程序,显然可以发送/接收文件,我想添加一种发送整个文件夹的方法。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
为此,您需要某种文件传输协议(即 FTP)。使用易于设置的 C# FTP 服务器库(即:http://sourceforge.net/projects/csftpserver/ )在发送端使用
FtpWebRequest
在客户端获取整个文件夹结构。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.使用著名的归档方法(zip、rar...)并传输数据。在对等端提取。这样你就可以节省:
递归模式。
Use famous archiving methods (zip, rar...) and transfer data. The extract the at the peer side. This way you save:
recursive pattern.
您是否为此目的查看了现有协议?看来你想克隆 FTP,也许使用像 tar 位于两者之间。
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.
如果您考虑压缩/压缩:
您可以查看 GZipStream 类。
http://www.geekpedia.com/tutorial190_Zipping-files-using-GZipStream.html
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