如何使用两个TCP连接创建FTP连接 [英] How to make a FTP Conncetion with two TCP connetion

查看:215
本文介绍了如何使用两个TCP连接创建FTP连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨;

我只想使用C#中的两个TCP连接建立一个FTP连接,

这是一个活动的FTP

我不知道该怎么写程序

这两个TCP连接来自客户端!

客户端(MY PC)与活动FTP服务器建立2个TCP连接,一个用于下载,一个用于上载!它们之间都有IP地址.这就是您尝试使用FTP连接的内容.


听起来您尝试做的事情无法完成.

一个TCP连接有两个末端,一个末端开始,另一个末端连接.建立连接后,数据就可以沿两种方式传递.

在活动FTP中,客户端与服务器建立连接.然后,服务器将任意数量的连接返回给客户端.这意味着您的从客户端到服务器的2个TCP连接模型(一个用于上载和一个用于下载)与同时来自客户端的连接均不匹配.

我怀疑您要执行的操作是使两个FTP会话到服务器.其中一个要上传而另一个要下载?

C#FTP客户端库 [ 解决方案

If the two machines have a TCP/IP connection between them, they both have an IP address. That''s what you attempt to connect to using FTP.


It sounds like what you are trying to do cannot be done.

A TCP connection has two ends, the one from which is starts and the one to which it connects. Once the connections established, then data can pass both ways along it.

In Active FTP, the client makes a connection to the server. Then the server makes any number of connections back to the client. This means that your model of 2 TCP connections from the client to the server, one for upload and one for download does not fit with the connections both coming from the client.

I suspect what you are trying to do is to make two FTP sessions to the server. One of these for upload and one for download?

There is an article here
C# FTP Client Library[^] which shows how to make an FTP session. I don''t know if it is what you want (it might not support active FTP even - but it is a start).

Once you have found a good way of making your ftp sessions then I would suggest that you simple create two of them. If you want them to work at the same time - then put them in different threads and use lock statements to create mutex code blocks for control between the two if required. Alternatively, use delegates to communicate between the threads.

Good luck :)


这篇关于如何使用两个TCP连接创建FTP连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆