Bonjour,
voila je suis en train de faire une petit application qui permet l'envoie de fichier sur mon serveur, la connexion se fait bien, mais l'upload ne fonctionne pas
ps: mon serveur est chez Power-Heberg
voici le code source
et voici le l'erreur qu il m'affiche
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110 import com.jcraft.jsch.*; import java.io.*; import java.util.*; /** * This class is used to demonstrate the usage of the * JCraft JSch package to SFTP files. * * @author Tim Archer 04/20/07 * @version $Revision: 1.1 $ */ public class TestJSch { /** Creates a new instance of TestCommonsNet */ public TestJSch() { } /** * main - Unit test program * @param args Command line arguments * */ public static void main(String args[]) { try { String ftpHost = "hote"; int ftpPort = 22; String ftpUserName = "login"; String ftpPassword = "pass"; String ftpRemoteDirectory = "/www/"; String fileToTransmit = "c:\\Users\\jeremie\\Documents\\texte.txt"; // //First Create a JSch session // System.out.println("Creating session."); JSch jsch = new JSch(); Session session = null; Channel channel = null; ChannelSftp c = null; // //Now connect and SFTP to the SFTP Server // try { //Create a session sending through our username and password session = jsch.getSession(ftpUserName, ftpHost, ftpPort); System.out.println("Session created."); session.setPassword(ftpPassword); //Security.addProvider(new com.sun.crypto.provider.SunJCE()); // //Setup Strict HostKeyChecking to no so we dont get the //unknown host key exception // java.util.Properties config = new java.util.Properties(); config.put("StrictHostKeyChecking", "no"); session.setConfig(config); session.connect(); System.out.println("Session connected."); // //Open the SFTP channel // System.out.println("Opening Channel."); channel = session.openChannel("sftp"); channel.connect(); c = (ChannelSftp)channel; } catch (Exception e) { System.err.println("Unable to connect to FTP server. "+e.toString()); throw e; } // //Change to the remote directory // System.out.println("Changing to FTP remote dir: " + ftpRemoteDirectory); c.cd(ftpRemoteDirectory); // //Send the file we generated // try { File f = new File(fileToTransmit); System.out.println("Storing file as remote filename: " + f.getName()); c.put(new FileInputStream(f), f.getName()); } catch (Exception e) { System.err.println("Storing remote file failed. "+e.toString()); throw e; } // //Disconnect from the FTP server // try { c.quit(); } catch (Exception exc) { System.err.println("Unable to disconnect from FTP server. " + exc.toString()); } } catch (Exception e) { System.err.println("Error: "+e.toString()); } System.out.println("Process Complete."); System.exit(0); } }
merci d'avance de vos solutions.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 Creating session. Session created. Session connected. Opening Channel. Unable to connect to FTP server. com.jcraft.jsch.JSchException: java.io.IOException: inputstream is closed Error: com.jcraft.jsch.JSchException: java.io.IOException: inputstream is closed Process Complete.
jerem721
Partager