views:

147

answers:

2

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.

A: 

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

Spencer Ruport
Okay, when I do that it freezes on the line that reads this.bytes = clientSocket.Receive and the this.bytes has a value of 21. Any ideas?private string readLine() { while (true) { this.bytes = clientSocket.Receive(this.buffer, this.buffer.Length, 0); this.message += ASCII.GetString(this.buffer, 0, this.bytes); ....
geoff
A: 

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.

Zepplock
But it hasn't logged in yet. It's in the first process of logging in and never returns from the password verification part of the login method.
geoff
You said in your post "when the program start uploading a file", maybe you meant "starts working"? Did you verify that the file is actually being uploaded. I also suggest capturing the ftp session using Ethereal/Wireshark and analyzing the trace.
Zepplock
Sorry, I misspoke/typed. It looks like it never gets past logging in.
geoff