简体   繁体   English

使用Java创建简单的ftp

[英]creating simple ftp using Java

Recently I was designing a simple ftp. 最近,我正在设计一个简单的ftp。 When a client connects to server, server create a special Socket for this connection: 当客户端连接到服务器时,服务器为此连接创建一个特殊的套接字:

Socket clientSocket = listenSocket.accept();

I want to use this socket to send commands to server and create a new one to send data. 我想使用此套接字将命令发送到服务器,并创建一个新的套接字来发送数据。 So I have two questions. 所以我有两个问题。

  1. Should I create a new socket for data only once, and remember reference, or create it whenever I need? 我应该只为数据创建一次新的套接字,并记住引用,还是在需要时创建它?
  2. How exactly can I Create it? 我究竟该如何创建它? On server side create a new Socket, and through clientSocket send a port number to client so it know which port it should use to send/receive data. 在服务器端创建一个新的套接字,并通过clientSocket向客户端发送端口号,以便它知道应使用哪个端口发送/接收数据。

Appreciate Your advice! 感谢您的建议!

You might look at the FTP spec here: http://tools.ietf.org/html/rfc959 Specifically, check out page 3. You'll see FTP has a passive data port which waits for connections in addition to the control connection. 您可以在此处查看FTP规范: http : //tools.ietf.org/html/rfc959具体来说,请查看第3页。您将看到FTP具有被动数据端口,除了控制连接外,它还等待连接。 Also, there is a diagram on page 7 which clarifies the typical FTP approach. 另外,第7页上的图阐明了典型的FTP方法。 Replicating it would certainly be a viable strategy. 复制它肯定是一个可行的策略。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM