in reply to script for accessing ftp servers
to debug FTP, either use an interactive FTP client or just as well your way described above, but aim low.
See if you get a connection working.
See if you get something back with the ls or dir methods/commands.
See if that makes sense. Then cd one level and repeat the ls or dir etc. until you successfully arrive where you wanted to go. Use what you have learned about the FTP server's structure and check, if you can shorten the path to one cd only.