C# ftp 客户端类的奇怪行为

发布于 2024-08-25 03:46:36 字数 972 浏览 5 评论 0原文

一年多前,我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故人爱我别走 2024-09-01 03:46:36

让它在调试模式下运行,当它冻结时点击暂停,这样您就可以准确地看到它挂在哪一行。

Let it run in debug mode and when it freezes hit pause so you can see exactly what line it's hung up on.

累赘 2024-09-01 03:46:36

如果它开始传输 - 则不需要再次登录,除非连接中断并且您的客户端尝试重新连接,这将导致重新登录。

我强烈建议查看客户端是否支持“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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文