IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

API standards et tierces Java Discussion :

Trasfert de fichiers via SFTP


Sujet :

API standards et tierces Java

  1. #1
    Membre averti
    Inscrit en
    Juin 2008
    Messages
    13
    Détails du profil
    Informations forums :
    Inscription : Juin 2008
    Messages : 13
    Par défaut Trasfert de fichiers via SFTP
    Salut à tous ,
    Je voudrais développer un client SFTP en windows qui envoie des fichier vers un serveur SFTP Unix . Mais je n'ai pas réussi à le faire . J'utilise dans cet exemple la bibliothèque sshtools :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    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
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
     
     
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import com.sshtools.j2ssh.SshClient;
    import com.sshtools.j2ssh.authentication.AuthenticationProtocolState;
    import com.sshtools.j2ssh.authentication.PasswordAuthenticationClient;
    import com.sshtools.j2ssh.io.UnsignedInteger32;
    import com.sshtools.j2ssh.session.SessionChannelClient;
    import com.sshtools.j2ssh.sftp.FileAttributes;
    import com.sshtools.j2ssh.sftp.SftpFile;
    import com.sshtools.j2ssh.sftp.SftpFileOutputStream;
    import com.sshtools.j2ssh.SftpClient;
    import java.io.*;
    import com.sshtools.j2ssh.configuration.ConfigurationLoader;
     
    public class SftpConnect {
     
      public static void main(String args[]) {
        try {
          ConfigurationLoader.initialize(false);
          BufferedReader reader =
              new BufferedReader(new InputStreamReader(System.in));
          System.out.print("Connect to host? ");
          String hostname = reader.readLine();
          // Make a client connection
          SshClient ssh = new SshClient();
          // Connect to the host
          ssh.connect(hostname);
          // Create a password authentication instance
          PasswordAuthenticationClient pwd = new PasswordAuthenticationClient();
          // Get the users name
          System.out.print("Username? ");
          String username = reader.readLine();
          pwd.setUsername(username);
          // Get the password
          System.out.print("Password? ");
          String password = reader.readLine();
          pwd.setPassword(password);
          // Try the authentication
          int result = ssh.authenticate(pwd);
          // Evaluate the result
          if (result == AuthenticationProtocolState.COMPLETE) {
            // The connection is authenticated we can now do some real work!
          SftpClient sftp = ssh.openSftpClient();
            // Make a directory
     
     try {
     
      sftp.mkdir("/home/j2ssh");
        }
         catch (IOException ex) {
     
           }
          //   Change directory
          sftp.cd("/home/j2ssh");
          System.out.println(sftp.pwd());
            // Change the mode
        sftp.chmod(777, "/home/j2ssh");
         sftp.lcd("c:/");
            // Upload a file
           sftp.put("bilel.txt", "/home/j2ssh/bilel.txt");
     
            // Quit
            sftp.quit();
            ssh.disconnect();
     
       }}
       catch (Exception e) {
     
         e.printStackTrace();
       }
      }
    }

  2. #2
    Membre averti
    Inscrit en
    Juin 2008
    Messages
    13
    Détails du profil
    Informations forums :
    Inscription : Juin 2008
    Messages : 13
    Par défaut
    Citation Envoyé par inzaghi Voir le message
    Salut à tous ,
    Je voudrais développer un client SFTP en windows qui envoie des fichier vers un serveur SFTP Unix . Mais je n'ai pas réussi à le faire . J'utilise dans cet exemple la bibliothèque sshtools :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    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
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
     
     
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import com.sshtools.j2ssh.SshClient;
    import com.sshtools.j2ssh.authentication.AuthenticationProtocolState;
    import com.sshtools.j2ssh.authentication.PasswordAuthenticationClient;
    import com.sshtools.j2ssh.io.UnsignedInteger32;
    import com.sshtools.j2ssh.session.SessionChannelClient;
    import com.sshtools.j2ssh.sftp.FileAttributes;
    import com.sshtools.j2ssh.sftp.SftpFile;
    import com.sshtools.j2ssh.sftp.SftpFileOutputStream;
    import com.sshtools.j2ssh.SftpClient;
    import java.io.*;
    import com.sshtools.j2ssh.configuration.ConfigurationLoader;
     
    public class SftpConnect {
     
      public static void main(String args[]) {
        try {
          ConfigurationLoader.initialize(false);
          BufferedReader reader =
              new BufferedReader(new InputStreamReader(System.in));
          System.out.print("Connect to host? ");
          String hostname = reader.readLine();
          // Make a client connection
          SshClient ssh = new SshClient();
          // Connect to the host
          ssh.connect(hostname);
          // Create a password authentication instance
          PasswordAuthenticationClient pwd = new PasswordAuthenticationClient();
          // Get the users name
          System.out.print("Username? ");
          String username = reader.readLine();
          pwd.setUsername(username);
          // Get the password
          System.out.print("Password? ");
          String password = reader.readLine();
          pwd.setPassword(password);
          // Try the authentication
          int result = ssh.authenticate(pwd);
          // Evaluate the result
          if (result == AuthenticationProtocolState.COMPLETE) {
            // The connection is authenticated we can now do some real work!
          SftpClient sftp = ssh.openSftpClient();
            // Make a directory
     
     try {
     
      sftp.mkdir("/home/j2ssh");
        }
         catch (IOException ex) {
     
           }
          //   Change directory
          sftp.cd("/home/j2ssh");
          System.out.println(sftp.pwd());
            // Change the mode
        sftp.chmod(777, "/home/j2ssh");
         sftp.lcd("c:/");
            // Upload a file
           sftp.put("bilel.txt", "/home/j2ssh/bilel.txt");
     
            // Quit
            sftp.quit();
            ssh.disconnect();
     
       }}
       catch (Exception e) {
     
         e.printStackTrace();
       }
      }
    }
    J'ai eu l'exception: Permission denied à la ligne 64 .

Discussions similaires

  1. [10g] Envoi des fichiers via SFTP : secure FTP
    Par Mhamed_dev dans le forum PL/SQL
    Réponses: 1
    Dernier message: 24/10/2014, 19h47
  2. Réponses: 0
    Dernier message: 14/10/2014, 12h21
  3. déplacement de fichier via sftp en script ksh
    Par saladin443 dans le forum AIX
    Réponses: 2
    Dernier message: 15/05/2013, 18h21
  4. Récupérer des fichiers via wget et SFTP
    Par JerryOne3 dans le forum Langages serveur
    Réponses: 1
    Dernier message: 26/12/2012, 13h13
  5. Comment copier un fichier via SFTP ?
    Par AAWOOPY56 dans le forum Solaris
    Réponses: 2
    Dernier message: 06/07/2009, 09h53

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo