what's the best way to get file/directory information that's supported on Unix/Linux remote host
<p>I have a python code that needs to get file or directory information on a remote host that's Unix/Linux (OS names: HP-UX/RedHat/SunOS/AIX/Linux/etc). </p>

<p>The program SSH into the remote host (using paramiko library) and executes <code>ls -l</code> or <code>ls -ld</code> depending on if it's a file or a directory.</p>

<p>Information I need are:</p>

<ol>
<li>Permission (user/group/other)</li>
<li>User owner</li>
<li>Group owner</li>
<li>Last Modified</li>
<li>File name</li>
</ol>

<p>However, the problems with <code>ls</code> are:</p>

<ol>
<li>Output is different from platform so special handling is needed which makes code verbose using checks.</li>
<li>File size unit may be different in the output depend on environment variable (for GNU coreutils, BLOCK_SIZE), or some may even not support this. This also requires platform-specific checks.</li>
</ol>

<p>I am looking for a python library or simple portable executable if there is one.</p>

<p>Solutions I considered (but seems infeasible)</p>

<ol>
<li>Use regex to check format of the output and process if it matches konwn format. However, this seems to be error prone due to try-checks.</li>
<li>Also try-check environment variables for the file size and found out the file size unit in the output. (e.g. echo few characters to a file and check the unit. If 4 char is written and size says 1 then I know for sure the unit is greater than 1 bytes. Repeat the steps). This seems to be also error prone</li>
<li>Install cross-platform compiler on each host, compile and then execute. Can't do it since if the host OS is reinstalled or restored to the point that doesn't have compiler, this installation process needs to be repeated.</li>
</ol>

<p>Any suggestions?</p>