Im working on writing an FTP application in C# to get a good
feeling for the .NET language and how threading / networking
classes all work. Thus far I have it working for the most
part in PASV mode. The only problem I have encountered is
when the server ends the connection, the
socket cant tell and attempts to continue reading data
infinitely.
Basically... in PASV mode, the FTP server opens a random
port > 1024 and the client connects to that port. When file
transfer is completed the server drops the connection on
that port. However... the port stays open for another
connection for data transfer.
So... what I think is happening is when the connection is
dropped, the socket reconnects and attempts to continue
reading data. There is no more data. I unfortunately can
not base breaking out of the loop based upon data being
available on the socket because it may take packets
longer than others to arrive.
There is a success message transferred to the control
connection of the FTP client upon success of the file
transfer. That means that the server has sent all the
packets out... but doesnt mean the client has recieved them
all.
I see my solutions as being setting a boolean variable upon
receipt of the success message from the server... but how
can I tell when the data is done???? Would I need to have a
timeout after an arbitrary amount of time??? Is there any
way to tell that the connection has dropped???
Apparantly the socket is reconnecting on its own after the
completetion of the data transfer... is there a way to set
it to NOT do this????