FTP Connection, Socket closes itself

Robert_Zenz

Well-known member
Joined
Jun 3, 2008
Messages
503
Location
Vienna, Austria
Programming Experience
3-5
Hello there.

I wrote my own FTP-Class to communicate and download files from an FTP, while yesterday in the morning everything worked great, my code started to get buggy in the afternoon (don't ask, I have no idea...).

I'm using the TCPClient to connect to the FTP Server, but for some reason the connection keeps closing itself at certain points. I already had a packet sniffer running which indicated the Reset is coming from MY end...which is, in fact, a little confusing.

This is the code which I'm using to receive data:
VB.NET:
        Dim buffer(size - 1) As Byte
        Dim ptr As Integer = 0
        Dim read As Integer = 0

        Do
            read = Me.prv_dataClient.Client.Receive(buffer, ptr, Me.prv_dataClient.ReceiveBufferSize, SocketFlags.Partial)
            ptr += read
        Loop While read > 0 AndAlso Me.prv_dataClient.Client IsNot Nothing AndAlso Me.prv_dataClient.Connected AndAlso Me.prv_dataClient.Available > 0

I'm using this code construct at every point if I want to receive data...the first 'wave' of data is coming in without any problems, but at soon as the Read command is executed the Socket (prv_dataClient.Client) dies and closes the connection. The Timeout is set to 3 seconds and the FTP-Server is working great with every other program...why is the connection dying?

Thanks in advance,
Bobby
 
Hello again...

it seems like that the problem is somewhere else...the above code keeps failing for all three, getting the server response, the filelist and the download of files.

However, this code works at least for the download:
VB.NET:
        Do
            read = Me.prv_dataClient.Client.Receive(buffer, ptr, size - ptr, SocketFlags.Partial)
            ptr += read
        Loop While read > 0 Or Me.prv_dataClient.Available > 0

But it does not work with the other two situations...this is somehow pretty odd...

Bobby
 
Back
Top