Everything seems correct, because when I try to use that code not in threading, then it works perfectly. I used 'GetLastError', after 'FtpPutFile' finishes, and I get 'Invalid handle', but handle is correct, because it works everywhere else.
One possible explanation is that each thread has its own stack. It may happen that the connection object was created in one thread's stack and it has been destroyed at the time when it is used in the other thread.