1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Rep Power

    Python File format check with FTP download


    I am using python's ftplib module for downloading several files in binary mode. The ftp server is windows whereas my client is on linux. The files are of different formats (e.g. raw text, zip archive, etc). At times, some of the downloaded files are not in the expected format. Does python already provide a functionality/module to check for the correct format of files when they get downloaded from ftp?

    Manually, I use 'file $filename' to test, but wondering about other/existing capabilities in python.

    I am running python v2.7.3.

    Thank You.
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Rep Power

    use the file command

    The file command looks at the magic bytes instead of the file extension to determine the file type.

    $ mv zippy.jpg myCatPhoto
    $ file myCatPhoto
    myCatPhoto: JPEG image data, EXIF standard 2.21
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo