PHP code example of osumionline / plugin-ftp
1. Go to this page and download the library: Download osumionline/plugin-ftp library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
osumionline / plugin-ftp example snippets
$ftp = new OFTP('host', 'user', 'password');
// Abrir conexión
if ($ftp->connect()) {
echo "Conexión abierta al servidor remoto.";
}
// Iniciar sesión
if ($ftp->login()) {
echo "Sesión iniciada."
}
// Establecer conexión pasiva
$ftp->passive(true);
// Desconectar la conexión automaticamente tras realizar un comando
$ftp->autoDisconnect(true);
// Establecer modo de conexión ('ascii' / 'bin')
$ftp->mode('bin');
// Comprobar si la conexión sigue abierta y reconectar en caso contrario
$ftp->checkConnection();
// Subir un archivo al servidor remoto
if ($ftp->put('/local/path/to/file.txt', '/remote/path/to/file.txt')) {
echo "Archivo subido correctamente.";
}
// Descargar un archivo del servidor remoto
if ($ftp->get('/remote/path/to/file.txt', '/local/path/to/file.txt')) {
echo "Archivo descargado correctamente.";
}
// Borrar un archivo del servidor remoto
if ($ftp->delete('/remote/path/to/file.txt')) {
echo "Archivo borrado correctamente.";
}
// Cambiar de ruta en el servidor remoto
if ($ftp->chdir('/remote/path/')) {
echo "Ruta cambiada correctamente.";
}
// Crear una carpeta en el servidor remoto
if ($ftp->mkdir('/remote/path/new/')) {
echo "Carpeta creada correctamente.";
}
// Cerrar conexión al servidor remoto.
$ftp->disconnect();