added ftp functions, reorganized code