December 24th, 2012, 11:57 AM
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, 09: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!