Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- *
- */
- class FtpTransfer
- {
- private $user;
- private $password;
- private $ftp_server;
- private $remote_dir;
- private $ftp_string;
- function __construct($server, $user, $password){
- $this->ftp_server = $server;
- $this->user = $user;
- $this->password = $password;
- $this->ftp_string = "ftp://$this->user:$this->password@$this->ftp_server";
- }
- function set_remote_dir($path){
- $this->remote_dir = $path;
- }
- function upload_curl($filename){
- if(file_exists($filename)){
- $ch = curl_init();
- $fp = fopen($filename, 'r');
- $remote_file = $this->$remote_dir.$filename;
- //echo "sending $remote_file to $ftp_string$remote_file\n";
- curl_setopt($ch, CURLOPT_URL, $this->ftp_string.$remote_file);
- curl_setopt($ch, CURLOPT_UPLOAD, 1);
- curl_setopt($ch, CURLOPT_INFILE, $fp);
- curl_setopt($ch, CURLOPT_INFILESIZE, filesize($filename));
- curl_exec ($ch);
- $error_no = curl_errno($ch);
- curl_close ($ch);
- if ($error_no == 0) {
- $error = "File $filename uploaded succesfully.\n";
- } else {
- $error = "File $filename upload error. \n";
- }
- echo "$error";
- }else{
- echo "The file doesn't exists...$filename\n";
- }
- }
- }
- //EXAMPLEE
- $ftp_server = "FTP_SERVER";
- $ftp_user_name = "USER_NAME";
- $ftp_password = "PASSWORD";
- $remote_dir = "REMOTE_DIR";
- $ftpTransfer = new FtpTransfer($ftp_server, $ftp_user_name, $ftp_password);
- $ftpTransfer->set_remote_dir = "REMOTE_DIR";
- $ftpTransfer->upload_curl("FILE_PATH");
- ?>
Add Comment
Please, Sign In to add comment