ftp_fget()返回传输完成错误

I'm trying to download images from a remote FTP server and upload them to our own rackspace account. This goes fine for about 3000 images but then it crashes and gives me the following error:

exception with message 'ftp_fget(): Transfer complete.'

We've tried changing the code to use ftp_get(), to not use a temp file to store it in, but it always resulted in the same error. It always fails on the same files, if I were to delete a couple of files that were already downloaded and run the scripts again it has no problem downloading them... it just fails again once it hits those specific images on the FTP server. I've tried downloading those images manually from the server and it worked, it seems nothing is wrong with them.

This is basically the code that does it:

$this->handle = ftp_connect($ftpurl);
$loggedIn = ftp_login($this->handle, $ftpusername, $ftppassword);
if ($loggedIn === false) {
    throw new Exception('Can\'t login to FTP server');
}
if ($this->handle === false) {
    throw new Exception('Could not connect to the given url');
}
ftp_pasv($this->handle, true);

$fileList = ftp_nlist($this->handle, '.');
if (count($fileList) === 0) {
    throw new Exception('No files found on FTP-server');
}

foreach($fileList as $filename) { 
    try {
        $container->getObject($filename);
        // Image already exists, rackspace has no convenient hasImage() function
    } catch (Exception $ex) {     
        $temp = tmpfile();
        ftp_fget($this->handle, $temp, $filename, FTP_BINARY);

        //upload $tmp to rackspace
    }
}

Any ideas what could be the issue here?