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
| public static String creer_rep(String hote, String login, String password, String chemin, String nom_repertoire) {
try {
//Configuration de l'hôte
HostConfiguration hostConfig = new HostConfiguration();
Protocol easyhttps = new Protocol("https",(ProtocolSocketFactory) new EasySSLProtocolSocketFactory(),443);
Protocol.registerProtocol("https", easyhttps);
hostConfig.setHost(hote, 443, easyhttps);
//On défini un HttpConnectionManager, qui permet de gérer les connexions, et éventuellement le multithreading
HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
int maxHostConnections = 20;
params.setMaxConnectionsPerHost(hostConfig, maxHostConnections);
connectionManager.setParams(params);
//On créé l'objet HttpClient et on lui passe les données d'authentification
HttpClient client = new HttpClient(connectionManager);
client.setHostConfiguration(hostConfig);
Credentials creds2 = new UsernamePasswordCredentials(login,password);
client.getState().setCredentials(AuthScope.ANY, creds2);
//Création du répertoire via la méthode MKCOL
EntityEnclosingMethod mkcol = new EntityEnclosingMethod(chemin + nom_repertoire){
public String getName() { return "MKCOL"; }
};
client.executeMethod(mkcol);
System.out.println("Répertoire " + chemin + nom_repertoire + " créé avec succès.");
mkcol.releaseConnection();
return "OK";
}
catch(IOException ioe) {
ioe.printStackTrace();
return ioe.toString();
}
} |
Partager