December 24th, 2012, 12:57 PM
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.
December 24th, 2012, 10:28 PM
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] are essential for python code and Makefiles!