The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

File Manager/File Transfers Adding Garbage to Files?

Discussion in 'General Discussion' started by randomuser, Oct 1, 2005.

  1. randomuser

    randomuser Well-Known Member

    Joined:
    Jun 25, 2005
    Messages:
    147
    Likes Received:
    0
    Trophy Points:
    16
    Hi,

    I am using the following:

    WHM 10.6.0 cPanel 10.6.0-R55
    RedHat Enterprise 3 i686 - WHM X v3.1.0


    After uploading a Python script to my website via cPanel's File Manager, the file will not properly execute. Note: python is installed, works, etc etc. This can be verified when I cat>file.py, chmod 755 file.py, and browse to it. With that out of the way, here is something I noticed:

    After uploading the file via cPanel's File Manager, look at this:

    # file hello.py
    script text executableython

    That is the exact output from the "file" command. Now, look at this:

    # strings hello.py > hello1.py
    # file hello1.py
    hello1.py: a /usr/bin/python script text executable

    hello1.py works just fine when I view it in my browser (after giving it executable permissions of course). There do not appear to be any differences between the files, other than the newlines being removed after running the strings command:


    # cat hello.py
    #!/usr/bin/python

    print "Content-Type: text/plain\n\n"

    print "Hello World\n";


    # cat hello1.py
    #!/usr/bin/python
    print "Content-Type: text/plain\n\n"
    print "Hello World\n";



    If I open hello.py in vi, I see no control characters, extra spaces anywhere, or any other extraneous characters. Note that the file hello.py was created in notepad, thus there are no control/formatting characters being added.


    And finally, we have this:

    # file hello.py
    script text executablethon
    (you've already seen that, but check out below)

    # file hello.py > a
    # file a
    a: ASCII text, with CR, LF line terminators
    # cat a
    script text executablethon
    # strings a
    hello.py: a /usr/bin/python
    script text executable


    All of the output you see above is exactly how it is being displayed from my end.

    This issue came up when a customer was attempting to copy a python script to her server earlier this evening, and receiving the exact same results - the file would not execute properly. The ownership/permissions/contents of the file were exactly correct, and exactly the same as what I have pasted in this thread. I have checked numerous times just to be sure my eyes were not deceiving me. However, when she uses WS_FTP to transfer (using ASCII mode - I do not know if she tried any other method), it works fine as expected.

    Can someone please tell me why using cPanel's File Manager prevents this from working? Or why the results would have been exactly the same when uploading the file via FrontPage? I'm 99.9% certain the file is being borked somehow during the transfer, but I have no idea how. I also had the user create the file in notepad and try the same method. Our results matched exactly. I am 100% positive she had the file in the correct location, with the correct permissions, and so on. I checked myself during every test we tried. Running strings on the file, and outputting to a new file worked every time.

    Any thoughts? Thanks.
     
  2. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    Go on, have a guess
    The problem is most likely because you're using notepad which is using Windows/DOS linefeeds instead of Linux ones. The cPanel filemanager uploads in BINARY mode and so won't fix them for you. What should work is if you edit the file after uploading in the filemanager and then simply save it and the linefeeds should be fixed. Alternatively, you should really use an FTP program to upload files and make sure that it is configured to upload .py files in ASCII mode.

    Lastly, you really ought to update your old cPanel installation :)
     
  3. randomuser

    randomuser Well-Known Member

    Joined:
    Jun 25, 2005
    Messages:
    147
    Likes Received:
    0
    Trophy Points:
    16
    Hi Chirpy,

    I agree that an FTP application should be used to transfer the files in ASCII mode, but using the File Manager was a last resort for a customer who had tried several ways already to transfer the file. She'd tried to "publish" via FrontPage (which I believe FTPs the file in binary mode - I know nothing about FrontPage), she also tried doing it (somehow) via My Network Connections in WindowsXP. I didn't get any clarification on that. So, lastly I recommended using File Manager.

    I had no idea there was a difference in line feeds between win32 and *nix. Now I know what all those ^M's are that I've seen in vi while using FBSD (due to files being transferred in binary mode).

    I'm guessing, and don't currently have the time to research much further, that the issue may have been this:

    From http://www.vim.org/tips/tip.php?tip_id=26:

    If that were the case, that would explain why, when opening both files in vi, there were no noticeable differences.

    Thanks for the explanation Chirpy. As always you've been very helpful, I appreciate it.
     
Loading...

Share This Page