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

Good morning Monks. I am having a rather strange problem. I generate a php file (a web page with an embedded logon script) then use Net-FTP to upload it like so:
unless ($suppressftp) { print "FTP starting...\n"; my $ftp = Net::FTP->new("ftp.mysite.com", Debug => 0) or die "Cann +ot connect to ftp.mysite.com: $!"; $ftp->login("uid",'password') or die "Cannot login ", $ftp->messag +e; $ftp->binary; $ftp->cwd("mydir") or die "Cannot change working directory ", $ftp +->message; $ftp->put("$filename\.php") or die "Can't put $filename\.php ", $f +tp->message; $ftp->cwd("gfx") or die "Cannot change working directory ", $ftp-> +message; for my $file ('g_f.png','g_m.png','g_p.png','g_r.png','g_t.png','s +eries_1.png','series_2.png') { print "...writing $file\n"; $ftp->put("gfx/$file") or die "Can't put gfx/$date$file ", $ftp->m +essage; } $ftp->quit; }

Everything uploads fine, but when I try to open the php file with my browser I get a php parse error ("extra $"). If I re-upload the same php file using an FTP client I have (WS-FTP) then the file opens fine.

I've tried uploading the php file in both text and binary mode, same result. Obviously Net-FTP is doing something bad to the php file when it uploads it. Has anyone had this problem or know how to fix?

thanks.....Steve

Replies are listed 'Best First'.
Re: Net-FTP corrupting php file
by davidrw (Prior) on May 23, 2005 at 13:45 UTC
    y, my first thought also was that the php file should be put across as text .. can you post the line of the php file that gives the parse error? That might show how the file was changed.. Actually, even better--can you diff the php file that was put up via Net::FTP against a good version that you put up there with WS-FTP?
      You mean compare the two files? Why didn't I think of that? When I did, I found the clue that let me discover the real prolem.

      Perhaps you will get a kick out of this: I had put the wrong file handle on a close command so the PHP file wasn't closed when Net::FTP uploaded it, and there was still a little text left in the buffer resulting in a truncated file. After the upload, PERL flushed the buffer and closed the file before shut down, so when I then uploaded the file with my FTP client it was the complete file and of course it worked.

      I hate it when that happens :-)

      Steve