When uploading and downloading a php file using ftp software, the line feed in the PHP file is lost.

Source: Internet
Author: User
Tags ftp php source code

When uploading and downloading php source files using ftp, we occasionally find the php file written in the notepad ++ editor in the local windows. After uploading the file to the linux server using ftp, all the linefeeds of the PHP file are lost, and the PHP file cannot run normally.
At this time, I downloaded the uploaded php file to the local windows using the ftp software again. After opening it with the notepad ++ editor, I found that the php source code was changed to a line and the line feed was lost.
What is the cause of this situation? It is easy to summarize in one sentence:
In linux, the line feed is n, while in windows, the line feed is rn. When ftp is uploaded, files are uploaded in ASCII mode by default, while files are uploaded in ASCII mode, the line breaks in the file are processed as appropriate to meet the running environment of the upload server. In this process, some files will be improperly handled, and the bug of loss of line breaks may occur. (Note that not all php files will cause this problem if a small part of PHP files exist ).
Appeal problems, especially when the php source code contains a single line annotator "//", will cause the php source file to be unable to run directly. Because after the source code is changed to a line of code, the single-line annotator has commented out all the code behind.
FTP upload bug solution:
Method 1: Change single-line annotator // to multi-line annotator/* comment text */so that even if the linefeed is lost, the subsequent source code execution is not affected. (But it is still a headache when downloading to a local machine for secondary modification !)
Method 2: Do not use the ASCII mode for uploading php files over FTP. This is the safest. How to set the ftp software to be uploaded in Binary format? Search the network for the setting method of the ftp software you are using.

[Knowledge addition: ASCII and Binary transmission modes of FTP ]:
FTP has two transmission modes: ASCII and Binary:
Binary mode does not process any data.
In Ascii mode, the carriage return line breaks into the local carriage return characters.
 
Because the line terminator of WINDOWS and UNIX is different. Therefore, ^ M may occur when a text file is transmitted to UNIX in Binary transmission mode in WINDOWS. When files are transmitted from UNIX to WINDOWS in Binary mode, incorrect line breaks may also occur.
 
The newly created ftp_ascii.txt in Windows is as follows:
Hello word!
Upload wd to unix!
Test ftp ascii;

We upload files to UNIX in two modes respectively.
Normal ASCII mode
Vi ftp_ascii.txt
Hello word!
Upload wd to unix!
Test ftp ascii;

Binary mode error
Vi ftp_ascii.txt
Hello word! ^ M
Upload wd to unix! ^ M
Test ftp Binary;
We can see that using ASCII mode to transmit text can avoid ^ M problems during transmission. Although the ASCII mode in FTP can avoid the problem of ^ M. However, the Binary method is used in most cases to ensure that the transmitted content is not changed. Most of the executable files, such as php source code, are transmitted using the binary method.
In FlashFXP, you can choose ASCII, BINARY, and automatic modes from menu> session> transmission mode.
In addition, when we log on to sftp over ssh to upload files, we can avoid the loss of line breaks.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.