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

Android Discussion :

Exécuter une commande SCP sous Android


Sujet :

Android

  1. #1
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2012
    Messages
    156
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Juin 2012
    Messages : 156
    Points : 59
    Points
    59
    Par défaut
    Bonsoir,

    J'essaye d'implémenter une méthode qui pourra executer une commande SCP ( copie d'un fichier csv du portable Android vers ma machine locale )

    Le code est comme suit:
    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
     
    public class ADBCommand {
               public String execute(String command) throws IOException {
     
    			String retour = "";
    			BufferedReader stdInput = null;
    			BufferedReader stdError = null;
     
    			System.out.println("execute process");
    			try {
     
    				Log.d(TAG, "Executing SCP command");
     
    				ProcessBuilder process = new ProcessBuilder("bash", "-c",
    						command); // to execute multiples commands
    				Map<String, String> env = process.environment();
    				process.redirectErrorStream(true);
    				Process p = process.start();
     
    				InputStream is = p.getInputStream();
    				InputStreamReader isr = new InputStreamReader(is);
    				stdInput = new BufferedReader(isr);
     
    				String line = "";
     
    				while ((line = stdInput.readLine()) != null) {
    					retour += line + "\n";
    					System.out.println("Results : " + retour);
    				}
     
    			} catch (Exception e) {
    				Log.e(ERROR, e.toString());
    			}
     
    			return retour;
    		}
    	}
     
    }
    Instantiation:

    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
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
     
    	String command1 = "chmod 777 " + path_to_sdcard + "/" + file_name;
    		String RunSCPcmd = "scp -i /data/data/id_rsa_android /mnt/sdcard/"
    				+ file_name
    				+ " nbrarou@10.4.0.10:WBESTGit/stage_nabil_brarou/Results";
     
    		String command = command1 + " ; " + RunSCPcmd;
     
                                    ADBCommand adb = new ADBCommand();
    				adb.execute(command);
    				Log.d(TAG, "Running Command " + command);
     
           }

    J'ai ça dans le LogCat:
    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
    11-19 17:49:15.530: D/wbest_server(27435): Executing SCP command
    11-19 17:49:15.580: I/System.out(27435): Results : FIX ME! implement ttyname() bionic/libc/bionic/stubs.c:432
    11-19 17:49:15.590: I/System.out(27435): Results : FIX ME! implement ttyname() bionic/libc/bionic/stubs.c:432
    11-19 17:49:15.590: I/System.out(27435): Unable to chmod /mnt/sdcard/wbest-estimation_2013-11-19.csv: Operation not permitted
    11-19 17:49:16.480: I/System.out(27435): Results : FIX ME! implement ttyname() bionic/libc/bionic/stubs.c:432
    11-19 17:49:16.480: I/System.out(27435): Unable to chmod /mnt/sdcard/wbest-estimation_2013-11-19.csv: Operation not permitted
    11-19 17:49:16.480: I/System.out(27435): /system/xbin/ssh: Failed to open /data/local/.ssh/known_hosts
    11-19 17:49:16.485: I/System.out(27435): Results : FIX ME! implement ttyname() bionic/libc/bionic/stubs.c:432
    11-19 17:49:16.485: I/System.out(27435): Unable to chmod /mnt/sdcard/wbest-estimation_2013-11-19.csv: Operation not permitted
    11-19 17:49:16.485: I/System.out(27435): /system/xbin/ssh: Failed to open /data/local/.ssh/known_hosts
    11-19 17:49:16.485: I/System.out(27435): Results : FIX ME! implement ttyname() bionic/libc/bionic/stubs.c:432
    11-19 17:49:16.485: I/System.out(27435): Unable to chmod /mnt/sdcard/wbest-estimation_2013-11-19.csv: Operation not permitted
    11-19 17:49:16.485: I/System.out(27435): /system/xbin/ssh: Failed to open /data/local/.ssh/known_hosts
    11-19 17:49:16.485: I/System.out(27435): Host '10.4.0.10' is not in the trusted hosts file.
    11-19 17:49:16.485: I/System.out(27435): Results : FIX ME! implement ttyname() bionic/libc/bionic/stubs.c:432
    11-19 17:49:16.490: I/System.out(27435): Unable to chmod /mnt/sdcard/wbest-estimation_2013-11-19.csv: Operation not permitted
    11-19 17:49:16.490: I/System.out(27435): /system/xbin/ssh: Failed to open /data/local/.ssh/known_hosts
    11-19 17:49:16.490: I/System.out(27435): Host '10.4.0.10' is not in the trusted hosts file.
    11-19 17:49:16.490: I/System.out(27435): (fingerprint md5 72:f6:7b:01:c0:06:b7:71:24:44:5d:e2:b7:d9:d7:e7)
    11-19 17:49:17.325: I/AudioPolicyManager(1874): stopOutput() output 1, stream 3, session 4623
    11-19 17:49:17.335: I/AudioPolicyManager(1874): startOutput() output 1, stream 3, session 4625
    11-19 17:49:17.335: D/AudioSystem(1874): android::AudioSystem::isSeparatedStream(audio_stream_type_t) called!
    y'a quelqu'un qui voit comment faire ?

    Merci.

  2. #2
    Expert éminent

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Points : 9 149
    Points
    9 149
    Par défaut


    chmod s'éxécute en étant root.

    Si ton but est de copier les fichier de la sdcard alors il te suffit juste de donner les droits a ton application de Lecture/Ecriture(a vérifier) sur la sdcard.
    android.permission.WRITE_EXTERNAL_STORAGE ou
    android.permission.READ_EXTERNAL_STORAG
    Responsable Android de Developpez.com (Twitter et Facebook)
    Besoin d"un article/tutoriel/cours sur Android, consulter la page cours
    N'hésitez pas à consulter la FAQ Android et à poser vos questions sur les forums d'entraide mobile d'Android.

Discussions similaires

  1. Impossible d'exécuter une commande scp
    Par keviin55 dans le forum Shell et commandes GNU
    Réponses: 1
    Dernier message: 19/07/2012, 18h24
  2. exécuter une commande sur tous les fichiers des sous dossiers
    Par Concombre Masqué dans le forum Shell et commandes GNU
    Réponses: 7
    Dernier message: 05/03/2009, 01h15
  3. exécuter une commande de logiciel
    Par MrsFrizz dans le forum C
    Réponses: 4
    Dernier message: 17/01/2006, 10h48
  4. exécuter une commande système à partir de sqlplus?
    Par c_moi_c_moi dans le forum Oracle
    Réponses: 24
    Dernier message: 08/11/2005, 15h11
  5. Exécuter une commande linux.
    Par casafa dans le forum Linux
    Réponses: 4
    Dernier message: 20/07/2005, 23h13

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