mget mput perl

mget mput perl - Perl - Programmation

Marsh Posté le 20-04-2009 à 17:20:37    

Salut,
 
Apparamment en perl avec le module Net::ftp,
on ne dipose pas du mget et mput;
sur le net il dise qu'il faut le programmer soit meme
 
et donne ceci
 

Code :
  1. sub mput {
  2.     my ( $ftp, $pattern ) = @_;
  3.     foreach my $file ( glob($pattern) ) {
  4.        $ftp->put($file) or warn $ftp->message;
  5.     }
  6. }
  7. sub mget {
  8.     my ( $ftp, $pattern ) = @_;
  9.     foreach my $file ( $ftp->ls($pattern) ) {
  10.         $ftp->get($file) or warn $ftp->message;
  11.     }
  12. }


 
je comprend pas trop ce code
 
merci de votre aides

Reply

Marsh Posté le 20-04-2009 à 17:20:37   

Reply

Marsh Posté le 20-04-2009 à 17:44:18    

c'est quoi que tu ne comprends pas dans ce code ?

Reply

Marsh Posté le 21-04-2009 à 08:15:10    

je comprends pas le glob
et ces fonctions prennent en parametre le patern et $ftp ?
 
si j'appel mget je dois le faire comme ceci
mget ($ftp,'*.txt');


Message édité par donny3 le 21-04-2009 à 08:20:39
Reply

Marsh Posté le 21-04-2009 à 10:10:00    

pour glob : http://perldoc.perl.org/File/Glob.html
ca permet une extension comme le ferait le csh
en langage humain ton "*.txt" fonctionnera
 
en perl, dans une procédure tous les paramètres sont récupérés depuis la variable interne @_ (si tu veux une liste) ou $_ (dans un contexte scalaire)
La ligne

Code :
  1. my ( $ftp, $pattern ) = @_;

permet de récupérer le premier paramètre dans $ftp, et le second dans $pattern
 
et oui, pour appeler les fonctions, il faut faire comme tu as dis

Reply

Marsh Posté le 21-04-2009 à 10:18:20    

merci
, j'avais compris pour le @_ ,je m etais mal exprimés.
par contre il y a un truc que je n'arrive pas à faire.
avec $ftp->code et $ftp-> message, je peux récuperer les codes retour de ftp et le message correspondant.
j'ai trouver un site ou il y avait la liste des codes, je sais pas si il y a tout les codes par contre.
Ce que je n'arrive pas à faire c'est tester le code et le message dansla fonction mget.
Quand je rajoute l'affichage du message dans ma fonction , elle m'affiche le message du dessus :
 
ex :

Code :
  1. $ftp->ascii();
  2. $code= $ftp->code();
  3. $message= $ftp->message;
  4. mget($ftp,'*.txt');
  5. sub mget {
  6.     my ( $ftp, $pattern ) = @_;
  7.     foreach my $file ( $ftp->ls($pattern) ) {
  8.         $ftp->get($file) or warn $ftp->message;
  9.        my $message = $ftp->message;
  10.      print "Message : $message\n";
  11.     }
  12. }


 
Je vais avoir le message ascii et pas le message du get.
Je ne pourrai pas savoir et avoir une trace si mon get en fonctionne pas/

Reply

Marsh Posté le 23-04-2009 à 01:50:49    

Pour la liste des codes, il suffit de compiler ceux donnés dans les 3 RFC du protocole FTP (959, 2228, 2640):

 

        110 Restart marker reply.
             In this case, the text is exact and not left to the
             particular implementation; it must read:
                  MARK yyyy = mmmm
             Where yyyy is User-process data stream marker, and mmmm
             server's equivalent marker (note the spaces between markers
             and "=" ).
         120 Service ready in nnn minutes.
         125 Data connection already open; transfer starting.
         150 File status okay; about to open data connection.

 

        200 Command okay.
         202 Command not implemented, superfluous at this site.
         211 System status, or system help reply.
         212 Directory status.
         213 File status.
         214 Help message.
             On how to use the server or the meaning of a particular
             non-standard command.  This reply is useful only to the
             human user.
         215 NAME system type.
             Where NAME is an official system name from the list in the
             Assigned Numbers document.
         220 Service ready for new user.
         221 Service closing control connection.
             Logged out if appropriate.
         225 Data connection open; no transfer in progress.
         226 Closing data connection.
             Requested file action successful (for example, file
             transfer or file abort).
         227 Entering Passive Mode (h1,h2,h3,h4,p1,p2).
         230 User logged in, proceed.
         232 User logged in, authorized by security data exchange.
         234 Security data exchange complete.
         235 [ADAT=base64data]
               ; This reply indicates that the security data exchange
               ; completed successfully.  The square brackets are not
               ; to be included in the reply, but indicate that
               ; security data in the reply is optional.
         250 Requested file action okay, completed.
         257 "PATHNAME" created.

 

        331 User name okay, need password.
         332 Need account for login.
         334 [ADAT=base64data]
               ; This reply indicates that the requested security mechanism
               ; is ok, and includes security data to be used by the client
               ; to construct the next command.  The square brackets are not
               ; to be included in the reply, but indicate that
               ; security data in the reply is optional.
         335 [ADAT=base64data]
               ; This reply indicates that the security data is
               ; acceptable, and more is required to complete the
               ; security data exchange.  The square brackets
               ; are not to be included in the reply, but indicate
               ; that security data in the reply is optional.
         336 Username okay, need password.  Challenge is "...."
               ; The exact representation of the challenge should be chosen
               ; by the mechanism to be sensible to the human user of the
               ; system.
         350 Requested file action pending further information.

 

        421 Service not available, closing control connection.
             This may be a reply to any command if the service knows it
             must shut down.
         425 Can't open data connection.
         426 Connection closed; transfer aborted.
         431 Need some unavailable resource to process security.
         450 Requested file action not taken.
             File unavailable (e.g., file busy).
         451 Requested action aborted: local error in processing.
         452 Requested action not taken.
             Insufficient storage space in system.

 

        500 Syntax error, command unrecognized.
             This may include errors such as command line too long.
         501 Syntax error in parameters or arguments.
         502 Command not implemented.
         503 Bad sequence of commands.
         504 Command not implemented for that parameter.
         530 Not logged in.
         532 Need account for storing files.
         533 Command protection level denied for policy reasons.
         534 Request denied for policy reasons.
         535 Failed security check (hash, sequence, etc).
         536 Requested PROT level not supported by mechanism.
         537 Command protection level not supported by security mechanism.
         550 Requested action not taken.
             File unavailable (e.g., file not found, no access).
         551 Requested action aborted: page type unknown.
         552 Requested file action aborted.
             Exceeded storage allocation (for current directory or
             dataset).
         553 Requested action not taken.
             File name not allowed.

 

        631 (integrity protected reply)
         632 (confidentiality and integrity protected reply)
         633 (confidentiality protected reply)


Et a priori, après exécution d'une commande ftp, on va récupérer le code avec $ftp->code.
A+,


Message édité par gilou le 23-04-2009 à 02:05:52

---------------
There's more than what can be linked! --    Iyashikei Anime Forever!    --  AngularJS c'est un framework d'engulé!  --
Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed