views:

198

answers:

1

I am trying to upload file to FTP server using php but it is not getting uploaded.

Code:

   $response =<<<RESPONSE
    <cdm:Response>
    <cdm:header exportTime="{$export_time}" baseVersion="{$baseline_snapshot_id}" version="{$this->snapshot_id}">
            <cdm:countryCode>{$this->domain}</cdm:countryCode>
            <cdm:description>{$description}</cdm:description>
            <cdm:environment>{$destination}</cdm:environment>
            <cdm:name>{$name}</cdm:name>
    </cdm:header>
    <cdm:Status>{$this->status}</cdm:Status>
    </cdm:Response>
    RESPONSE;

   $handler = fopen($log_file_name, 'w');
   fwrite($handler, $response);
   fclose($handler);

   $server = "adoshi.dev.com";
   $ftp_user_name = "adoshi";
   $ftp_user_pass = "*******";
   #$source = $handler;
   $mode = "FTP_ASCII";
   $dest = "/home/adoshi/ftp_folder";
   $connection = ftp_connect($server);
   $login = ftp_login($connection, $ftp_user_name, $ftp_user_pass);
   if (!$connection || !$login) { die('Connection attempt failed!'); }
   $upload = ftp_nb_put($connection, $dest, $handler, $mode);
   if (!$upload) { echo 'FTP upload failed!'; }
   ftp_close($connection);

I have provided all login credentials proper and so still wondering that why it is not uploading to remote server using php.

Any guidance would be highly appreciated.

A: 

You dont need to create a file handler to upload them you just need the path to that file and the filename like this

$destFile= "test.htm";
$lokal_file = "test.htm";
$upload = ftp_put ($connection_id, $destFile, $lokal_file, FTP_ASCII);
streetparade
I tried doing this but still it is not working out for me. Thing is am not getting any kind of errors and so am not able to track what is actually happening.
Rachel
did you tryed adding this to your script? error_reporting(E_ALL);ini_set('display_errors', '1');
streetparade
i did this but still no errors and so wondering that why is this happening...
Rachel
hy again you have an syntax error in your code look for this line : $upload = ftp_nb_put($connection, $dest, $handler, $mode); and change it to $upload = ftp_put($connection, $dest, $handler, $mode); and dont forget to accept the answer regard streetparade
streetparade