Jump to content

ftp conection


raduenea

Recommended Posts

Hy

 

I have a script to upload a file on server.

The folder where the file is on server have chmod=0755.

So a made a class ftp to make the folder 777, upload the file and then to change to 755.

 

here is the class:

class ftp{

   var $conect;
   var $poze_mici;
   var $poze_mari;

   function conFTP() {
   
      // Set up variables 
      $host = 'ftp.xxx.com'; // host (website) that contains the folder you want to change 
      $user = 'username'; // username to log onto the host 
      $password = password; // password to log onto the host 
      $pix_lit = 'public_html/reviste/pix_lit/';
      $pix_big = 'public_html/reviste/pix_big/'; 
       // folder name to change 
      //$mod = '0777'; // permissions to be set
      
      // connect to FTP site 
      $conn = ftp_connect("$host");
      
      if (!$conn) 
      {
      
      echo 'Error: Could not connect to ftp server';
      
      exit; 
      }
      
      // log in to FTP site 
      @ $result = ftp_login($conn, $user, $password);
      
      if (!$result) 
      {
      
      echo "Error: Could not log on as $user";
      
      ftp_quit($conn);
      
      exit; 
      }
      
      $this->conect = $conn;
      $this->poze_mici = $pix_lit;
      $this->poze_mari = $pix_big;

   }

   function openFTP() {

      ftp_site($this->conect, 'CHMOD 0777 '.$this->poze_mici); 
      ftp_site($this->conect, 'CHMOD 0777 '.$this->poze_mari);
   }
   
   function closeFTP() {
   
      // close the connection
      ftp_site($this->conect, 'CHMOD 0755 '.$this->poze_mici); 
      ftp_site($this->conect, 'CHMOD 0755 '.$this->poze_mari);
      
      ftp_close($this->conect);   
   
   }
}

 

And here is where upload file:

require("../functions.php");

$ftp = new ftp();
$ftp->conFTP();
$ftp->openFTP();

// here upload the file

$ftp->closeFTP();

 

the openftp change to 777. But closeftp function don't change back to 755. The folde remain to 777.

 

Any sugentions?

Thanks

 

Link to comment
https://forums.phpfreaks.com/topic/144307-ftp-conection/
Share on other sites

With this class all I want is: before I upload a file on server on the specific folder I want to change the permission of the file to 0777 with this function $ftp->openFTP();

 

After the file is uploaded I want to chabged back to 0755 with this function $ftp->closeFTP();

 

I'm doing this because I need to change de permission of the folder to have the rights to write, and after that changed back.

Link to comment
https://forums.phpfreaks.com/topic/144307-ftp-conection/#findComment-757635
Share on other sites

I am the owner of the file. The default value of the folder on server is 0755.

With this function ($ftp->openFTP();) I change to 0777 and the change is make perfectly.

I upload the file in that folder and it uploaded ok.

Then I change back to 0755 with $ftp->closeFTP(); but it dosen't change. The folder remain with 0777.

 

Is something wrong with the code but I don't know that is it.

Link to comment
https://forums.phpfreaks.com/topic/144307-ftp-conection/#findComment-757949
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.