What do the log files on the other ftp servers (that don't work) say? Do they even show a login attempt? Is it always one particular ftp server that works when you hard code its details? Do you get any error messages on screen when you run your script?