haaglin Posted October 2, 2007 Share Posted October 2, 2007 Hi. I have a wierd problem i hope you can help me with. I have a CMS system that uses php's ftp functions to keep the file ownership to the user, not apache. So when a file is uploaded, it is uploaded to a temp directory, and i use "ftp_put" to move it to the right position, with correct ownership. However, i installed the system on a server today, and when i upload php files using this method, it adds empty lines between every line. this does not happen to other non-binary files like javascript files. I have used this method for a long time, and i have never seen this before. Some info: Transfer mode is FTP_ASCII Server is running suPHP (Is this the problem?) Example: (before transfer) <?php $line = "just an example"; $line2 = "just an example too"; echo "This is ".$line; echo "This is ".$line2; ?> (after transfer) <?php $line = "just an example"; $line2 = "just an example too"; echo "This is ".$line; echo "This is ".$line2; ?> This might not seem like a "problem", but i do have som code that cant have empty lines. Quote Link to comment https://forums.phpfreaks.com/topic/71513-solved-ftp_put-adds-empty-lines-between-every-line-on-upload/ Share on other sites More sharing options...
shocker-z Posted October 2, 2007 Share Posted October 2, 2007 whats your code for uploading the file? also why does it need to be ran on suPHP? if you log into the FTP server as the user then it will be under their permissions anyway..? Liam Quote Link to comment https://forums.phpfreaks.com/topic/71513-solved-ftp_put-adds-empty-lines-between-every-line-on-upload/#findComment-359996 Share on other sites More sharing options...
MadTechie Posted October 2, 2007 Share Posted October 2, 2007 try switching to FTP_BINARY.. also on some FTP server theirs an option to resolve this, its a common problem when a file is written on a Macintosh then opened on a PC, Quote Link to comment https://forums.phpfreaks.com/topic/71513-solved-ftp_put-adds-empty-lines-between-every-line-on-upload/#findComment-359997 Share on other sites More sharing options...
haaglin Posted October 2, 2007 Author Share Posted October 2, 2007 whats your code for uploading the file? also why does it need to be ran on suPHP? if you log into the FTP server as the user then it will be under their permissions anyway..? Liam suPHP was not my choice, but the server i installed it on was running it, and i cant keep rewriting the cms everytime a customer has a host with suPHP. The code for uploading is just a normal upload to a temp dir, and then i use ftp_put to move it to the desired location from the temp dir. and then i delete the file from the temp dir when finished. Nothing special to it.. try switching to FTP_BINARY.. also on some FTP server theirs an option to resolve this, its a common problem when a file is written on a Macintosh then opened on a PC, Why FTP_BINARY? a php script is not binary, and should be transferred as ASCII. I use Linux, so the file is written on linux. the server is also running linux. I have opened the file in the same program the file is written on. Quote Link to comment https://forums.phpfreaks.com/topic/71513-solved-ftp_put-adds-empty-lines-between-every-line-on-upload/#findComment-360017 Share on other sites More sharing options...
Rithiur Posted October 2, 2007 Share Posted October 2, 2007 Why FTP_BINARY? a php script is not binary, and should be transferred as ASCII. I use Linux, so the file is written on linux. the server is also running linux. I have opened the file in the same program the file is written on. There is no harm done in transferring files as binary and it's the only way to ensure that the files remain intact. The ASCII transfer mode allows the software to "translate" the files to fit for the recieving operating system, i.e. modify the line endings to what the operating system uses. This causes some rather weird behavior sometimes (for example CRLF translates to CRCRLF on Linux -> Windows) If you want to find more information, I would recommend checking what kind of line endings the file originally has (such as if you editor is using something nonstandard for the operating system) and what kind of line endings the file has after the extra lines are there. Using binary transfer is, however, much easier option, as it will ensure there is no magical behavior. Quote Link to comment https://forums.phpfreaks.com/topic/71513-solved-ftp_put-adds-empty-lines-between-every-line-on-upload/#findComment-360028 Share on other sites More sharing options...
MadTechie Posted October 2, 2007 Share Posted October 2, 2007 its true script should be sent via ASCII, and uploading via BINARY can cause problems (ie error 500) but its worth a shot, i have used it a few time.. infact i have had to upload a zip and use the server tools to unzip the files to get them to work on a server. thats why i said "Try" switching to binary Quote Link to comment https://forums.phpfreaks.com/topic/71513-solved-ftp_put-adds-empty-lines-between-every-line-on-upload/#findComment-360031 Share on other sites More sharing options...
haaglin Posted October 2, 2007 Author Share Posted October 2, 2007 Okay.. I didn't know that. I will try the binary transfer and see how that works. Hopefully that will do the trick. Btw. I use Kate as editor. dont think there is anything special about is as it is for editing source files like php. Quote Link to comment https://forums.phpfreaks.com/topic/71513-solved-ftp_put-adds-empty-lines-between-every-line-on-upload/#findComment-360034 Share on other sites More sharing options...
haaglin Posted October 4, 2007 Author Share Posted October 4, 2007 try switching to FTP_BINARY.. also on some FTP server theirs an option to resolve this, its a common problem when a file is written on a Macintosh then opened on a PC, I switched to binary and you are right, the file is not touched. Any idea how this can happen? The server is running ProFTPD 1.3.0, which is the same as my own server, and my server does not touch the files in ASCII mode. Quote Link to comment https://forums.phpfreaks.com/topic/71513-solved-ftp_put-adds-empty-lines-between-every-line-on-upload/#findComment-361547 Share on other sites More sharing options...
MadTechie Posted October 4, 2007 Share Posted October 4, 2007 Hummm, i use ProFTPD as well, i could have a play when i'm at home (in the office at the moment), other things to play with would be Passive FTP.. (mainly when a firewall cause problems) Quote Link to comment https://forums.phpfreaks.com/topic/71513-solved-ftp_put-adds-empty-lines-between-every-line-on-upload/#findComment-361567 Share on other sites More sharing options...
haaglin Posted October 4, 2007 Author Share Posted October 4, 2007 I tried passive mode too, but the problem is still there. I have tried all i can think of, and binary mode seems to be the only way to keep the files intact. But i had some problems some time ago with binary mode on ascii files, that is why i really want to find the problem.. The strange thing is if i have a *.js file written on the same editor as the php files, the js file is not changed, only php files, and the only difference i know in the servers, is that the server with the problem is running suPHP. Thanks so far Quote Link to comment https://forums.phpfreaks.com/topic/71513-solved-ftp_put-adds-empty-lines-between-every-line-on-upload/#findComment-361578 Share on other sites More sharing options...
MadTechie Posted October 4, 2007 Share Posted October 4, 2007 i had a problem before with uploads but that was an access right problem, i see what i can come up with.. Quote Link to comment https://forums.phpfreaks.com/topic/71513-solved-ftp_put-adds-empty-lines-between-every-line-on-upload/#findComment-361584 Share on other sites More sharing options...
haaglin Posted October 11, 2007 Author Share Posted October 11, 2007 I discovered something strange. Files written in windows is not changed, only the files written on a linux enviroment. So it must have something to do with the line endings. In the settings of my editor, line endings are set to UNIX. With FTP_BINARY, i now get a 500 internal server errror sometimes. Quote Link to comment https://forums.phpfreaks.com/topic/71513-solved-ftp_put-adds-empty-lines-between-every-line-on-upload/#findComment-366961 Share on other sites More sharing options...
haaglin Posted October 11, 2007 Author Share Posted October 11, 2007 Problem solved. This is a reply i got from the host (Translated to english): According to hexdump, the file uses wierd line shifts: 0000000 3f3c 0a0d 2a2f 2d2d 2d2d 2d2d 2d2d 2d2d 0000010 2d2d 2d2d 2d2d 2d2d 2d2d 2d2d 2d2d 2d2d The first line, including lineshift is made of 4 octals: 0x3F, 0x3C, 0x0A, 0x0D. This represents the ASCII-values "<", "?", LF, CR (LF = line feed, CR = carriage return). This means that the lineshift is made of octals LF, CR. Standard lineshift: - Unix: LF (line feed => 0x0A => 10) - Windows/DOS: CR, LF (carriage return, line feed => 0x0D, 0x0A => 13, 10 Så the problem is that KATE (The editor i use), does something to my files, even when lineshift is set to Windows/DOS. I guess i have to ask in another forum how to solve that problem. (Altough any advice here is very welcome ) This command fixes the files, but when i open the files in kate, and save. the file is "corrupted" again cat before.php | sed 's/^M//g' > after.php (^M is made of CTRL+V + CTRL+M) Thanks everyone. Quote Link to comment https://forums.phpfreaks.com/topic/71513-solved-ftp_put-adds-empty-lines-between-every-line-on-upload/#findComment-367005 Share on other sites More sharing options...
MadTechie Posted October 11, 2007 Share Posted October 11, 2007 With FTP_BINARY, i now get a 500 internal server errror sometimes. i was worried about that.. windows machines add /r/n the end of the line, while *nix only adds /n (also a Macintosh only adds /r) try saving as text-only Quote Link to comment https://forums.phpfreaks.com/topic/71513-solved-ftp_put-adds-empty-lines-between-every-line-on-upload/#findComment-367010 Share on other sites More sharing options...
haaglin Posted October 11, 2007 Author Share Posted October 11, 2007 Actually, i solved it right after i posted. I removed the "Remove spaces after line endings" and its now saving the files correctly. All that is left now is to write a function that recursivly converts all my files (and thats a lot of files) Quote Link to comment https://forums.phpfreaks.com/topic/71513-solved-ftp_put-adds-empty-lines-between-every-line-on-upload/#findComment-367015 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.