简体   繁体   English

终止ftp服务器上的数据传输时的客户端行为

[英]Client behaviour when aborting data transfer on ftp server

Well, I am writing a multithreaded FTP server and now I am trying to implement data transfer abortion. 好吧,我正在编写一个多线程FTP服务器,现在我正在尝试实现数据传输中止。 This is a part of my code managing data transfer abortion. 这是我管理数据传输中止的代码的一部分。

ABORCommand(); //sends message with code 226 (1st message)
pthread_join(threads, &ret);  //waits for the thread processing data transfer

sprintf(buffer, "226 Transfer complete - %d bytes copied.\r\n", data_comm->num_bytes);
Send(); //this just sends the message in buffer to the client (2nd message)
WriteToLog("transfer complete", "226");

close(data_comm->clie_sock);   //closes the data connection
delete data_comm;  //this deletes instance of the class taking care of data transfer
  1. My problem is that the two clients I am testing (Nautilus and gftp client) behave differently when aborting data transfer. 我的问题是,中止数据传输时,我正在测试的两个客户端(Nautilus和gftp客户端)的行为不同。
  2. What I am trying to achieve is to be able to abort data transfer process with no errors using different clients. 我要实现的目标是能够使用其他客户端在没有错误的情况下中止数据传输过程。
  3. The behaviour of the clients depends on the messages I send them. 客户端的行为取决于我发送给他们的消息。
  4. When I abort the transfer with Nautilus, it work fine, no errors, no leaks. 当我用Nautilus中止传输时,它工作正常,没有错误,没有泄漏。 But with gftp client, the client recieves the first message and then closes control connection. 但是对于gftp客户端,客户端会收到第一条消息,然后关闭控件连接。 Then the server sends the second message to the client. 然后,服务器将第二条消息发送给客户端。 After that, the server is supposed to recieve something from the client, but when it happens, I get an error and a ton of mem leaks. 在那之后,服务器应该可以从客户端接收到一些信息,但是当发生这种情况时,我会收到错误消息,并出现大量内存泄漏。 I know that reading from closed socket gives error but it shouldn't crash the whole program. 我知道从封闭的套接字读取会产生错误,但它不应使整个程序崩溃。
  5. I tried to make the abortion work for the gftp client and the only (partial) solution was to send only the second message (well, I think it doesn't matter which one I send the point is to send just one of them). 我试图使gftp客户端可以使用堕胎,唯一的(部分)解决方案是仅发送第二条消息(嗯,我认为发送哪一条消息并不重要,只发送其中一条即可)。 I didn't get any errors after that and no mem leaks. 之后,我没有收到任何错误,也没有内存泄漏。 The only problem left was that the client still closed the control connection. 剩下的唯一问题是客户端仍然关闭了控制连接。 The server then closed the connection on it's end, because the client apparently disconnected (even the gftp client wrote "Disconnecting from site localhost"), but after the server closes it, gftp writes "Error: Remote site localhost disconnected. Will reconnect in 30 seconds". 然后服务器关闭了它的连接,因为客户端显然已断开连接(即使gftp客户端写了“从站点本地主机断开连接”),但是服务器关闭后,gftp则写了“错误:远程站点本地主机断开了连接。将在30秒”。
  6. The solution however had a side effect. 然而,该解决方案具有副作用。 The Nautilus client stopped working. Nautilus客户端停止工作。 The client recieved the message ,but was still waiting for another one (or so I think), because I sent him just one message. 客户收到了该邮件,但仍在等待另一封邮件(或者我认为是),因为我只向他发送了一封邮件。
  7. My question is how is it possible to make it work for both clients? 我的问题是如何使这两个客户都能使用? The only idea I have is that maybe the reply code is wrong. 我唯一的想法是,也许回复代码是错误的。 Please, tell me where the problem lies. 请告诉我问题出在哪里。

Thanks 谢谢

Ok, first you are true : 好吧,首先你是对的:

I get an error and a ton of mem leaks. 我收到一个错误,并出现大量内存泄漏。 I know that reading from closed socket gives error but it shouldn't crash the whole program 我知道从封闭的套接字读取会产生错误,但它不应使整个程序崩溃

So yes : 是的:

  • you should be resistant to errors : systematically checks for return codes and handle them correctly 您应该容忍错误:系统地检查返回码并正确处理它们
  • you should not have memory leaks : use smart pointers so that unused memory blocks are freed 您不应该发生内存泄漏:使用智能指针,以便释放未使用的内存块

And also, in a general manner : 并且,以一般方式:

  • your server should never expect clients to behave correctly. 您的服务器永远不要期望客户端行为正确。 On the contrary, it should assume that clients are buggy or even hostile (security). 相反,应该假定客户端有故障,甚至是敌对的(安全性)。 So you should have timeouts if clients don't answer. 因此,如果客户不回答,您应该超时。
  • if a client doesn't respect the specification but should still work (big market share) then you must find a way to recognize this client and behave accordingly. 如果客户不遵守规范但仍然可以工作(很大的市场份额),那么您必须找到一种方法来识别该客户并相应地表现。

After that, I don't understand your problem very well. 在那之后,我不太了解您的问题。 So see my comments and I will update this answer. 因此,请参阅我的评论,我将更新此答案。

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

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