Dynadot โ€” .com Registration $8.99

FTP using PHP

Spaceship Spaceship
Watch
Impact
49
Code:
<?php
$pixelURL='http://www.bluesnews.com/images/bluesLogo.gif'; // example external image
$ftp_server = 'ftp.com';
$ftp_user_name = 'myusername';
$ftp_user_pass = 'mypassword';
$conn_id = ftp_connect($ftp_server);
$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";
    }
$target_path = "/home/mypath/www/img/subdir/";
$destination_file = $target_path . 'fakefilename.gif';
// upload the file
$upload = ftp_put($conn_id, $destination_file, $pixelURL, FTP_BINARY); 
echo '<p>'.print_r($upload).'</p>';
// check upload status
if (!$upload) { 
        echo "FTP upload has failed!";
    } else {
        echo "Uploaded $source_file to $ftp_server as $destination_file";
    }

// close the FTP stream 
ftp_close($conn_id);
?>

The Output is:

Connected to ftp.com, for user username

1 // output of print_r($upload)

FTP upload has failed!

I really dont know what is happening...really appreciate if someone could find a solution. Thanks!!!
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Have you tried uploading a fuile that is on the local server with the code?

You seem to be trying to upload a file that is on an external site (or at least using a URL)
 
0
•••
peter@flexiwebhost said:
Have you tried uploading a fuile that is on the local server with the code?

You seem to be trying to upload a file that is on an external site (or at least using a URL)
That would do it :sick:



$pixelURL = file_get_contents('http://www.bluesnews.com/images/bluesLogo.gif');
 
0
•••
From PHP.net website:
Sometimes a web host will open PHP sessions with a user of 'nobody'. Files created by this user may not have the correct permissions to allow management of those files by the actual owner of the site. The following script allows the actual owner to open access to a directory so that 'nobody' can create a file using fopen(). Then using the handle created by 'nobody', the ftp_fput() command saves the file with the correct owner. The file 'nobody' created is discarded.

Code:
<?
    $connection = ftp_connect($ftpServer);
    ftp_login($connection, $ftpUser, $ftpPass);
    ftp_chdir($connection, $ftpDir);
    // open the directory so that 'nobody' can create a temporary file    
    ftp_site($cn, "CHMOD 777 $ftpDir");
    $new="tempFile";
    @unlink($new); // just in case
    $handle=fopen($new,"x");
    chmod($new,0777);
    fputs($handle,"a bunch of stuff...");
    fclose($handle); // have to rewind 
    $handle=fopen("tempFile","r");
    ftp_fput($connection, "finalFile", $handle, FTP_ASCII);
    fclose($handle);
    unlink($new);
    // remove open access to the directory
    ftp_site($connection, "CHMOD 755 $ftpDir")
    ftp_close($connection);
?>
 
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Appraise.net
Unstoppable Domains
Domain Recover
DomainEasy โ€” Live Options
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back