Commandes SITE

Retourne un tableau des commandes SITE disponibles sur un serveur FTP.

Auteur : Cedric Fronteau

1 806  vues
Compatibilité du code
PHP 5, PHP 7 et PHP 8
  code classé dans   FTP
  code source classé dans   FTP
 
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
                    
<?php
/*------------------------------*/
/*
Titre : Commandes SITE

Date édition : 14 Fev 2019
*/
/*------------------------------*/

function ftpsite_commands($host , $user , $passwd , $port=21){
$fp = fsockopen($host, $port, &$errno, &$errstr, 2);
if(!$fp)
return "$errstr ($errno)";

fgets($fp, 128);
fputs($fp, "USER $user\r\n");
fgets($fp, 128);
fputs($fp, "PASS $passwd\r\n");
$err = fgets($fp, 128);
if (preg_match("/login[\s]incorrect/i", $err))
return "Login incorrect";
fputs($fp, "SITE HELP\r\n");

socket_set_timeout($fp, 3, 0);
$lines = array();
do
{
$r = fgets($fp, 128);
if (!preg_match("/(214)?[- ]?(The following|Direct comments)/i", $r))
$lines[] = $r;
$arr = socket_get_status($fp);
} while ($arr['timed_out'] != 1);
fclose($fp);

$commands = array();
foreach($lines as $line)
{
$line = trim($line);
if ($line != '')
{
$tab_line = preg_split('/[-\s]/', $line, -1, PREG_SPLIT_NO_EMPTY);
foreach($tab_line as $command)
if(preg_match("/[A-Z]+/", $command))
$commands[] = $command;
}
}
return $commands;
}

?>
<?php
/*------------------------------*/
/*
Titre : Commandes SITE

Date édition : 14 Fev 2019
*/
/*------------------------------*/

function ftpsite_commands($host , $user , $passwd , $port=21){
$fp = fsockopen($host, $port, &$errno, &$errstr, 2);
if(!$fp)
return "$errstr ($errno)";

fgets($fp, 128);
fputs($fp, "USER $user\r\n");
fgets($fp, 128);
fputs($fp, "PASS $passwd\r\n");
$err = fgets($fp, 128);
if (preg_match("/login[\s]incorrect/i", $err))
return "Login incorrect";
fputs($fp, "SITE HELP\r\n");

socket_set_timeout($fp, 3, 0);
$lines = array();
do
{
$r = fgets($fp, 128);
if (!preg_match("/(214)?[- ]?(The following|Direct comments)/i", $r))
$lines[] = $r;
$arr = socket_get_status($fp);
} while ($arr['timed_out'] != 1);
fclose($fp);

$commands = array();
foreach($lines as $line)
{
$line = trim($line);
if ($line != '')
{
$tab_line = preg_split('/[-\s]/', $line, -1, PREG_SPLIT_NO_EMPTY);
foreach($tab_line as $command)
if(preg_match("/[A-Z]+/", $command))
$commands[] = $command;
}
}
return $commands;
}

?>

      Fonctions du code - Doc officielle PHP

   php.net  
Description
Versions PHP
    array
Crée un tableau
PHP 4, 5, 7 et 8
    fclose
Ferme un fichier
PHP 4, 5, 7 et 8
    fgets
Récupère la ligne courante à partir de l'emplacement du pointeur sur fichier
PHP 4, 5, 7 et 8
    fputs
Alias de fwrite
PHP 4, 5, 7 et 8
    fsockopen
Ouvre un socket de connexion Internet ou Unix
PHP 4, 5, 7 et 8
    preg_match
Effectue une recherche de correspondance avec une expression rationnelle standard
PHP 4, 5, 7 et 8
    preg_split
Éclate une chaîne par expression rationnelle
PHP 4, 5, 7 et 8
    return
Retourne le controle du programme au module appelant
PHP 4, 5, 7 et 8
    socket_get_status PHP 4, 5, 7 et 8
    socket_set_timeout PHP 4, 5, 7 et 8
    trim
Supprime les espaces en début et fin de chaîne
PHP 4, 5, 7 et 8
Minimum 10 mots. Votre commentaire sera visible après validation.


 Autres snippets qui pourraient vous intéresser

Redirection PHP ancien site vers nouveau site

Compatibilité : PHP 5, PHP 7, PHP 8

Il arrive que l'on doive faire une redirection définitive d'un ancien site vers un nouveau. Il faut alors mettre en place une redirection 301 sur chaque page.

Script PHP statistiques de fréquentation d'un site

Compatibilité : PHP 5, PHP 7, PHP 8

Ce script compte les visites sur votre site (1 ip / jour). On peut afficher ensuite les résultats sur une période donnée (par jour, mois ou années)

* Requêtes exécutées avec Recherche Contextuelle

  Les derniers scripts

PHP 8.5.5

logo PHP
Langue langue us
Date 12 Avril
Taille 32 Mo
Catégorie PHP

PHP 8.4.20

logo PHP
Langue langue us
Date 12 Avril
Taille 30 Mo
Catégorie PHP

Serendipity 2.6.0

logo Serendipity
Langue langue fr
Date 11 Avril
Taille 15 Mo
Catégorie Blogs

Drupal 11.3.6

logo Drupal
Langue langue us
Date 11 Avril
Taille 34 Mo
Catégorie CMS

TYPO3 14.2.0

logo TYPO3
Langue langue fr
Date 10 Avril
Taille 38 Mo
Catégorie CMS

Dolibarr ERP 23.0.1

logo Dolibarr ERP
Langue langue fr
Date 09 Avril
Taille 89 Mo
Catégorie Logiciels