Jump to content

Recommended Posts

I wrote this script earlier, and it was working, but I found out it wasn't naming the files right, so I fixed that, and when I upload it back to the server and tested it, it doesn't like the foreach, and that's because $file is returning a bool (false) isntead of an array.

 

It was working earlier so I don't know what's up.  I've already tried making it pasv.

 

Here's the script running: http://www.clanxmc.com/pb/getSS.php

 

<?php
error_reporting(6143);
/**
* @author Xodus
* @copyright 2007
* FTP TRANSFER!
*/

$ftp_server = "69.65.32.219";
$ftp_user_name = "2574";
$ftp_user_pass = "******";
$remoteSSPath = "/";

$destination_file = "./Unsorted/";

// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// check connection
if ((!$conn_id) || (!$login_result))
{
    echo "FTP connection has failed!";
    echo "Attempted to connect to $ftp_server for user $ftp_user_name";
    exit;
}
else
{
    echo "Connected to $ftp_server, for user $ftp_user_name";
}

$file = ftp_nlist($conn_id, $remoteSSPath);

echo "<br>";

var_dump($file);

foreach ($file as $files)
{
    $ispng = false;
    $findMe = "png";
    $ispng = strpos($files, $findMe);
    $newName = rand(1, 1000000);
    $newName .= ".png";
    if ($ispng)
    {

        ftp_rename($conn_id, $files, $newName);

        $get = ftp_get($conn_id, $destination_file . $newName, $newName, FTP_BINARY);

        if (!$get)
        {
            echo "FTP download has failed downloading: $newName!<br>";
        }
        else
        {
            echo "Downloaded $files to $destination_file <br>";
            echo "Deleting $files:<br>";

            if (ftp_delete($conn_id, $newName))
            {
                echo "$newName Deleted! <br>";
            }
            else
                echo "Error deleting file!";
        }
    }
    else
    {
        echo "$files is not a .png file! - Not downloading <br>";
        echo "Deleting $files:<br>";
        if (ftp_delete($conn_id, $files))
        {
            echo "$files Deleted! <br>";
        }
        else
            echo "Error deleting file!";

    }
}

ftp_close($conn_id);
echo "<br>Closed FTP Session<br>";
?>

 

Any help would be appreciated.

Thanks,

Xodus

Link to comment
https://forums.phpfreaks.com/topic/63295-problem-with-ftp_nlist-suddenly/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.