CMD Prompt > FTP Size Command

Posted by Samuel Baldus on Stack Overflow See other posts from Stack Overflow or by Samuel Baldus
Published on 2010-10-05T12:24:52Z Indexed on 2011/02/12 7:25 UTC
Read the original article Hit count: 217

Filed under:
|
|
|

I'm developing a PHP App on IIS 7.5, which uses PHP FTP commands.

These all work, apart from ftp_size().

I've tested:

cmd.exe > ftp host > username > password > SIZE filename = Invalid Command

However, if I access the FTP site through an Internet Browser, the filesize is displayed.

Do I need to install FTP Extensions, and if so, which ones and where do I get them?

Here is the PHP Code:

<?php
// FTP Credentials
$ftpServer = "www.domain.com";
$ftpUser = "username";
$ftpPass = "password";

// Unlimited Time
set_time_limit(0);

// Connect to FTP Server
$conn = @ftp_connect($ftpServer)
or die("Couldn't connect to FTP server");

// Login to FTP Site
$login = @ftp_login($conn, $ftpUser, $ftpPass)
or die("Login credentials were rejected");

// Set FTP Passive Mode = True
ftp_pasv ($conn, true);

// Build the file list
$ftp_nlist = ftp_nlist($conn, ".");

// Alphabetical sorting
sort($ftp_nlist);

// Display Output
foreach ($ftp_nlist as $raw_file) {
    // Get the last modified time
    $mod = ftp_mdtm($conn, $raw_file);
    // Get the file size
    $size = ftp_size($conn, $raw_file);
    // Size is not '-1' => file
      if (!(ftp_size($conn, $raw_file) == -1)) {
        //output as file
        echo "Filename: $raw_file<br />";
        echo "FileSize: ".number_format($size, '')."Kb</br>";
        echo "Last Modified: ".date("d/m/Y H:i", $mod)."</br>";
      }
}
?>

© Stack Overflow or respective owner

Related posts about php

Related posts about ftp