Viewing file: ftp_hacia_hostmonster.php (3.36 KB) -rw-rw-r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
if (!$_REQUEST['file']) { echo "fichero no especificado"; die(); }
$ftp_server = "ftp.papyrefb2.com"; // add server name $ftp_user_name = "[email protected]"; // add user name $ftp_user_pass = "_Ilvm2rg2"; // add password $dst_dir = "/public_html/torrebrunofiles/files/"; // add destination directory ( www/upload/ ) $ftp= new ftp($ftp_server,$ftp_user_name,$ftp_user_pass,$dst_dir); $ftp->ls(); echo "<pre>"; print_r($ftp); $directorio_origen="./recopilatorios_semanales_nuevos/"; $archivo_origen=$_REQUEST['file']; echo "subiendo $archivo_origen"; $ftp->sendfile($archivo_origen,$directorio_origen.$archivo_origen); $ftp->ls(); print_r($ftp); class ftp { public $ftp_server; public $ftp_user_name; public $ftp_user_pass; public $dst_dir; public $conn_id; public $login_result; public $mi_error; public $error=false; public $listadirectorio; function ftp($ftp_server,$ftp_user_name,$ftp_user_pass,$dst_dir) { if ($ftp_server!="" && $ftp_user_name!="" && $ftp_user_pass!="" && $dst_dir!="") { $this->ftp_server = $ftp_server; $this->ftp_user_name = $ftp_user_name; $this->ftp_user_pass = $ftp_user_pass; $this->dst_dir = $dst_dir; } else return false; // bad parametrs if (!$this->connect()){ echo "bad connect"; return false; } if (!$this->setdir()){ echo "no exist directory "; return false; } return true; // ALL OK }
/* FTP connect */ function connect() { $this->conn_id = ftp_connect($this->ftp_server); $this->login_result = ftp_login($this->conn_id, $this->ftp_user_name, $this->ftp_user_pass); if ((!$this->conn_id) || (!$this->login_result)) return false; else return true; } function disconnect() { return(ftp_close($this->conn_id)); }
/* Set Directory */ function setdir() { if (!ftp_chdir($this->conn_id, $this->dst_dir)){ $this->mi_error="no se pudo cambiar el directorio"; $this->error=true; return false; }else{ // echo ftp_pwd($this->conn_id); return true; } }
/* Send file */ /* INPUT: $remote_file -> file for send $file -> read file $mode -> "FTP_BINARY","FTP_ASCII",... */ function sendfile($remote_file, $file, $mode="FTP_BINARY") { if (!ftp_put($this->conn_id, $remote_file, $file, FTP_BINARY)){ $this->mi_error="no se pudo subir {$remote_file} {$file}"; $this->error=true; return false; }else{ return true; } } function getfile($local_file,$remote_file,$mode="FTP_BINARY") { $this->error=false; if (!ftp_get($this->conn_id, $local_file, $remote_file, FTP_BINARY)){ $this->mi_error="no se pudo bajar {$remote_file} {$file}"; $this->error=true; return false; }else{ $this->error=false; return true; } } function delete($file) { if (!ftp_delete($this->conn_id, $file)) { $this->mi_error="no se pudo borrar {$file}"; $this->error=true; return false; }else{ return true; }
} function ls() { $this->listadirectorio=ftp_nlist($this->conn_id, ftp_pwd($this->conn_id)); } function rename($oldname, $newname) { if (!ftp_rename($this->conn_id, $oldname, $newname) ){ $this->mi_error="no se pudo cambiar el nombre {$oldname} al nuevo: {$newname}"; $this->error=true; return false; }else{ return true; } }
} //end class ?>
|