Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

ftp script problem .. bad interpreter?

by Anonymous Monk
on Apr 18, 2005 at 09:22 UTC ( [id://448761]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi there. Right now I have a simple perl script that I'm trying to use to download some files from a FTP server, but for some reason that i don't understand it says ..
: bad interpreter: No such file or directory
When I try to run it. I have checked the location of both the ftp program and perl interpreter and they are both correct, and they are both definately installed and running just fine on my machine. I have no clue as to what is going on. The code is below
#!/usr/bin/perl $pdblist = $ARGV[0]; $ftp = "/usr/bin/ftp"; $ftptmp1="filename1.txt"; $ftphost1 = "ftp.rcsb.org"; $ftpdir1 = "pub/pdb/data/structures/all/pdb/"; $pdb = "pdb"; $ent = ".ent"; open(PDBLIST, "$pdblist") || die "ERROR: Unable to open $pdblist FILE: + $!\n"; print "$pdblist\n" while(<PDBLIST>) { @fields = split; $pdbname = $fields[0]; $pdbname =~ tr/[A-Z]/[a-z]/; $pdbfile = "$pdb$pdbname$ent"; # get pdb file from ftp site print "Retrieving $pdbfile file from FTP site ...\n"; open(FTP, "|$ftp -n $ftphost1 > $ftptmp1"); print FTP "user anonymous "; print FTP "password a.l.cuff\@qmul.ac.uk\n"; print FTP "cd $ftpdir1\n"; print FTP "bin\n"; print FTP "get $pdbfile\n"; print FTP "bye"; $pdbfileunzipped = substr($pdbfile, 0, 11); print "Decompressing $pdbfileunzipped ... \n"; system("gunzip $pdbfile"); }
Can anyone see something wrong with this that I'm not seeing? Any help much appreciated. Thank you.

Replies are listed 'Best First'.
Re: ftp script problem .. bad interpreter?
by PodMaster (Abbot) on Apr 18, 2005 at 09:32 UTC

      None of those seemed to have the easiest solution that I know of -- add two dashes at the end of the shebang line:

      #!/usr/bin/perl --

      This tells the system to ignore anything after that point, so even if you accidentally upload a file from windows to unix in binary mode, it'll run just fine. (although, I don't have a windows machine on the network right now, and I've never tested it with pod, <<EOF blocks, or other multiline strings, which are the only parts of Perl code that might depend on lines being read correctly.)

      It should, at the very least, result in better error messages, though, even if it doesn't fix the problem.

Re: ftp script problem .. bad interpreter?
by davidj (Priest) on Apr 18, 2005 at 09:31 UTC
    This is most likely the result of a file with dos newline encoding being executed on a Unix machine. The easy way to fix it is to use the dos2unix command. It will change the newline encoding to the Unix format and the script should run fine.
    dos2unix filename


    davidj
      Thanks DavidJ, much appreciated :)
Re: ftp script problem .. bad interpreter?
by inman (Curate) on Apr 18, 2005 at 10:54 UTC
    As a side note - have you looked at using Net::FTP instead of using the system FTP command? It will give you better access to error handling etc.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://448761]
Approved by ghenry
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-25 15:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found