C# ftp 客户端类的奇怪行为
一年多前,我在 C# 中发现了一个 ftp 客户端类,并且一直在每晚上传文件的过程中使用它。几天前,我们开始遇到一个超时的问题。我对此不太熟悉,所以我不确定它为什么这样做。
当程序开始上传文件时,它会检查是否已登录,如果没有,则调用登录方法。该方法中就是这段代码。
if (this.resultCode != 230)
{
this.sendCommand("PASS " + password);
if (!(this.resultCode == 230 || this.resultCode == 202))
{
this.cleanup();
throw new FtpException(this.result.Substring(4));
}
}
在写着 this.sendCommand("PASS"... 的行上,它进入了这段代码。
private void sendCommand(String command)
{
if (this.verboseDebugging) Debug.WriteLine(command, "FtpClient");
Byte[] cmdBytes = Encoding.ASCII.GetBytes((command + "\r\n").ToCharArray());
clientSocket.Send(cmdBytes, cmdBytes.Length, 0);
this.readResponse();
}
如果我让程序运行,它会超时。但是,如果我单步执行它到 sendCommand 方法,它执行得很好。有谁知道为什么当我单步执行时它会正常工作吗?我们端没有任何改变,并且我被告知客户端没有任何改变,所以我很困惑,谢谢。
I found an ftp client class in c# over a year ago and have been using it in a process that uploads files on a nightly basis. A few days ago we started having a problem where it would time out. I'm not well versed in this so I'm not sure why it's doing this.
When the program starts uploading a file it checks to see if it's logged in and if not, it calls the login method. In that method is this block of code.
if (this.resultCode != 230)
{
this.sendCommand("PASS " + password);
if (!(this.resultCode == 230 || this.resultCode == 202))
{
this.cleanup();
throw new FtpException(this.result.Substring(4));
}
}
On the line that says this.sendCommand("PASS"... it goes into this code.
private void sendCommand(String command)
{
if (this.verboseDebugging) Debug.WriteLine(command, "FtpClient");
Byte[] cmdBytes = Encoding.ASCII.GetBytes((command + "\r\n").ToCharArray());
clientSocket.Send(cmdBytes, cmdBytes.Length, 0);
this.readResponse();
}
If I let the program run, it times out. However if I step through it into the sendCommand method it executes fine. Does anyone know why it would work fine when I step through it? Nothing on our end has changed and I've been told nothing on the client's end has changed so I'm stumped. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
让它在调试模式下运行,当它冻结时点击暂停,这样您就可以准确地看到它挂在哪一行。
Let it run in debug mode and when it freezes hit pause so you can see exactly what line it's hung up on.
如果它开始传输 - 则不需要再次登录,除非连接中断并且您的客户端尝试重新连接,这将导致重新登录。
我强烈建议查看客户端是否支持“NOOP”命令(用于在通过数据连接传输数据时保持控制连接处于活动状态)。这是 FTP 实施中最常见的问题。
If it starts the transfer - it'll not need to login again, unless the connection interrupts and your client tries to reconnect which will result in relogin.
I strongly suggest into looking if the client supports "NOOP" command (used to keep the control connection alive while the data is transferred over data connection). That's the most common problem with FTP implementations.