Jump to content

FTP Get


Asheeown

Recommended Posts

Nothing in php.ini that says I can't download anywhere this big of a file so thats not the problem, I reversed the script and told it to put this time and still it outputted false, I'm starting to think that it might be logged in as a guest or something and just can't download or do anything, is their a way to check the status of the connection?

Link to comment
https://forums.phpfreaks.com/topic/38817-ftp-get/page/2/#findComment-187626
Share on other sites

<?php
include("include/Config.php");
// Set Variables
$Server = "***.***.***.***";					// Remote Server
$Username = "********";							// Remote Server Username
$Password = "*********";					// Remote Server Password
$Directory = "***";							// Remote Server Directory
$Type = "Raw"; 								// Example: Raw
$Table = "sansay_raw";						// CDR Table name
$LocalDirectory = "CDRS/";				// CDR Local Directory

// Do not change anything below this line
$LocalDirectory = $LocalDirectory . $Type;
$FtpConnect = ftp_connect($Server);
$Login = ftp_login($FtpConnect, $Username, $Password);

ftp_chdir($FtpConnect, $Directory);
echo "Current Directory: ";
echo ftp_pwd($FtpConnect);
echo "<br /><br /><br />";
$Files = ftp_nlist($FtpConnect, ".") or die("Line 21");


foreach($Files as $f) {
$Remote = "/$Directory/$f";
$Local = "$f";
$LocalF = fopen($Local,'w');
echo "File: $Remote is being written as $Local<br>";
if(ftp_fget($FtpConnect, $LocalF, $Remote, FTP_BINARY)) {
	echo "File: $Remote was downloaded successfully";
} else {
	echo "File: $Remote was not downloaded";
}
fclose($LocalF);

}
ftp_close($FtpConnect);
?>

 

Absolutely everything on the page, all personal information *ed

Link to comment
https://forums.phpfreaks.com/topic/38817-ftp-get/page/2/#findComment-187660
Share on other sites

I edited the code slightly to only try and download the files we want but it works perfectly for me remotely to my FTP:

foreach($Files as $f) {
        $Remote = "/$Directory/$f";
        $Local = "$f";
        if( preg_match( '/\.(cdr|php|txt|jpg|jpeg|gif)$/i', $Local ) )
        {
                $LocalF = fopen($Local,'w');
                echo "File: $Remote is being written as $Local<br>";
                if(ftp_fget($FtpConnect, $LocalF, $Remote, FTP_BINARY)) {
                        echo "File: $Remote was downloaded successfully";
                } else {
                        echo "File: $Remote was not downloaded";
                }
                fclose($LocalF);
        }

}

Link to comment
https://forums.phpfreaks.com/topic/38817-ftp-get/page/2/#findComment-187668
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.