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

    Join Date
    Dec 2012
    Posts
    1
    Rep Power
    0

    Python File format check with FTP download


    Hi,

    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 Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480

    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