Add main loop

Fix some ftp bugs