I've been trying to code a little ftp-client lately for fun,
So far it only logs in and send pasv-cmd and open data connection, and then list-cmd to get the directory.

It worked with some ftp-servers, but with some - after the data channel was closed, I never got the

"226 Transfer complete." - reply on port 21 socket, and couldn't send or receive any more commands..

I looked for a bug for over a week in a little ftp-client app, it made me crazy!!
Then just by chance I inserted a closesocket on the datasocket after it received a FD_CLOSE,
and everything worked!! *relief!!*

I had thought a socket shut down by the other side, was automatically closed.

Anyways, strange it still worked with some ftp's and some others not, while not closing that data-socket. (why?)

I tried look at packets with a sniffer-tool, and found some empty packets being sent, , packages, I think,
but I don't know about them, what they do..

So Now I wonder, does closesocket send some packet like this to the other side, maybe the server was waiting to get some
package like that before going on?
And what are the use of these syn, ack packages and the like, and what winsock actions send them...?
Posted on 2003-01-12 06:31:37 by david
PSDK: An application should always have a matching call to closesocket for each successful call to socket to return any socket resources to the system.

AFAIK FD_CLOSE indicates the connection itself is closed so it should work even without the closesocket (closesocket implicitly closes the connection but that's not its main function). However as the PSDK states, you need to close each socket handle anyway.

About the ACK/SYN package stuff: these packets are lower level packets, you don't have to worry about them when using winsock, its not your task.

Posted on 2003-01-12 14:13:34 by Thomas
Aha, ok, thanks
then it's maybe just my own program not working unless I close the socket.
Posted on 2003-01-13 05:05:42 by david