TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 09-03-2010, 04:41 PM   #1 (permalink)
The Wanderer
 
Join Date: Jul 2010
Posts: 17
Thanks: 0
Arictos is on a distinguished road
Default 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.
Arictos is offline  
Reply With Quote
Old 09-03-2010, 10:19 PM   #2 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

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 );
}
__________________
uʍop ǝpısdn sı ɹǝʇndɯoɔ ɹnoʎ sıɥʇ pɐǝɹ uɐɔ noʎ ɟı
delayedinsanity is offline  
Reply With Quote
Old 09-03-2010, 10:24 PM   #3 (permalink)
The Wanderer
 
Join Date: Jul 2010
Posts: 17
Thanks: 0
Arictos is on a distinguished road
Default

The link most definitely works, now errors are being thrown from my construct, and it returns as a valid resource.
Arictos is offline  
Reply With Quote
Old 09-03-2010, 10:32 PM   #4 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

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.
__________________
uʍop ǝpısdn sı ɹǝʇndɯoɔ ɹnoʎ sıɥʇ pɐǝɹ uɐɔ noʎ ɟı
delayedinsanity is offline  
Reply With Quote
Old 02-18-2012, 10:16 PM   #5 (permalink)
The Wanderer
 
AxelG's Avatar
 
Join Date: Feb 2012
Posts: 16
Thanks: 0
AxelG is on a distinguished road
Default

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);

AxelG is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Issues Karl Feedback 38 04-06-2013 05:03 AM
cross browser issues Evulness XHTML, HTML, CSS 5 08-18-2008 04:18 PM
mkdir permission issues Jako General 0 07-28-2008 02:28 AM
How to fix 95% of the cross-compatibility issues Wildhoney XHTML, HTML, CSS 25 12-15-2007 04:38 AM
Anybody having any connection issues with TalkPHP? Wildhoney Feedback 20 12-12-2007 01:30 PM


All times are GMT. The time now is 09:10 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design