TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Issues with FTP_GET (http://www.talkphp.com/general/5561-issues-ftp_get.html)

Arictos 09-03-2010 04:41 PM

Issues with FTP_GET
 
I'm having a particularly interesting issue with the ftp_get function. The code I use in this example is:

PHP Code:

/**
 * Downloads a file from the ftp server and saves it to a file
 * 
 * @var        string        Local file that you wish to write to
 * @var        string        Remote file to process contents from
 * @var        integer        FTP Mode
 * @var        bool        Returns true on sucess, or false of failure
 */
public function get($local_file$remote_file$mode FTP_BINARY)
{
    if(
is_file($local_file))
    {
        
unlink($local_file);    
    }
    
    if(
ftp_get($this->link$local_file$remote_file$mode))
    {
        return(
true);
    }
    
    return(
false);


The issue i'm having, is the file connection is solid, the file is downloaded properly, but the file ends up being empty. The file on the server is definitely populated with data, and is easily downloaded with a normal ftp client with all the data.

I've tried using both FTP_BINARY and FTP_ASCII, without a change in either. Any help would be appreciated.

delayedinsanity 09-03-2010 10:19 PM

Are you sure your link property is a valid resource? While you're at it, there's no need to unlink() anything as ftp_get() will overwrite an existing file.

php Code:
public function get( $local, $remote, $mode = FTP_BINARY )
{
    return ( is_resource( $this->link ) ? ftp_get( $this->link, $local, $remote, $mode ) : false );
}

Arictos 09-03-2010 10:24 PM

The link most definitely works, now errors are being thrown from my construct, and it returns as a valid resource.

delayedinsanity 09-03-2010 10:32 PM

I would double and triple check the paths and filenames. If the ftp connection is opening properly and it's returning a blank file, my first assumption would be that it's downloading a non-existent file on the remote end.

AxelG 02-18-2012 10:16 PM

Your file is empty because you do not have open it

PHP Code:

/**
 * Downloads a file from the ftp server and saves it to a file
 * 
 * @var        string        Local file that you wish to write to
 * @var        string        Remote file to process contents from
 * @var        integer        FTP Mode
 * @var        bool        Returns true on sucess, or false of failure
 */
public function get($local_file$remote_file$mode FTP_BINARY)
{
    if(
is_file($local_file))
    {
        
unlink($local_file);    
    }
    
$stream = @fopen($local_file'wb');
    if (!
$stream) {
        echo(
"Cannot open file: $local_file");
        return(
false);
    }
    
$download ftp_get($this->link$stream$remote_file$mode);
    
fclose($stream);
    if(
$download)
    {
        return(
true);
    }
    return(
false);




All times are GMT. The time now is 12:56 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0