Scripts fail to execute after upload

更新时间:
复制 MD 格式

After you upload a script file to a Linux web hosting instance, dependent website features may fail. This can happen if the script file uses an incorrect text format, which prevents Linux text editors from correctly recognizing the line break characters in the file. This topic explains the cause and solution.

Symptoms

After editing a script file in DOS format on a Windows computer, you upload it to a Linux web hosting instance with an FTP client. You then find that the script's functions do not work on your website.

Cause

An incorrect file upload mode in your FTP client causes this issue. When a script file is uploaded in a text mode that preserves Windows-style line endings, a Linux host cannot correctly interpret them, leading to script execution failures. The key differences are:

  • Windows uses a carriage return and a line feed character (\r\n) to mark the end of a line. In hexadecimal, this is 0D 0A.

  • Linux uses only a line feed character (\n) to mark the end of a line. In hexadecimal, this is 0A.

Solution

  1. Open your FTP client.

    This guide uses FileZilla version 3.66.5 as an example. Steps for other FTP clients may vary.

  2. From the top menu bar, select Edit > Settings....

  3. In the Settings dialog box, from the left pane, select Transfers > FTP: File Types.

  4. In the Default transfer type section, select Binary, and then click OK.

  5. Upload the file again and verify that the script runs correctly.

    If the issue persists, submit a ticket.