Guest User

Untitled

a guest
Jun 29th, 2018
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. <%@page import="java.util.Collections"%>
  2. <%@page import="org.apache.commons.io.*"%>
  3. <%@page import="java.io.File"%>
  4. <%@page import="java.io.File"%>
  5. <%@page import="com.jcraft.jsch.*"%>
  6. <%@page import="java.util.Vector"%>
  7. <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  8. pageEncoding="ISO-8859-1"%>
  9.  
  10. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  11. <html>
  12. <head>
  13. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  14. <title>Insert title here</title>
  15. </head>
  16. <script>
  17. function download(fn) {
  18. alert("downloading: " + fn);
  19. }
  20. </script>
  21. <body>
  22. <%
  23. String filname;
  24. String username = request.getParameter("username");
  25. if (null == username)
  26. username = "";
  27.  
  28. String password = request.getParameter("password");
  29. if (null == password)
  30. password = "";
  31.  
  32. String host = request.getParameter("host");
  33. if (null == host) {
  34. host = "";
  35. }
  36. String portStr = request.getParameter("port");
  37. if (null == portStr)
  38. portStr = "";
  39. int port = 0;
  40. try {
  41. port = Integer.parseInt(portStr);
  42. } catch (Exception ex) {
  43. }
  44.  
  45. String folder = request.getParameter("folder");
  46. if (null == folder) {
  47. folder = "";
  48.  
  49. String download = request.getParameter("dwnld");
  50. boolean flag = false;
  51. if (download != null) {
  52. flag = true;
  53. }
  54. }
  55. %>
  56.  
  57. <form method="POST">
  58. <table>
  59. <tr>
  60. <th align="right">SFTPHOST</th>
  61. <td><input name="host" value=<%=host%> size="50" type="text"></td>
  62. </tr>
  63. <tr>
  64. <th align="right">Username</th>
  65. <td><input name="username" value="<%=username%>"></td>
  66. </tr>
  67. <tr>
  68. <th align="right">Password</th>
  69. <td><input name="password" value="<%=password%>"
  70. type="password"></td>
  71. </tr>
  72. <tr>
  73. <th>Port</th>
  74. <td><input type="number" name="port" size="4" value="<%=port%>" /></td>
  75. </tr>
  76. <tr>
  77. <th>Working Directory</th>
  78. <td><input name="folder" value="<%=folder%>" size="100" /></td>
  79. </tr>
  80. <p style="color: red">Please provide full path</p>
  81. <tr>
  82. <td colspan="2"><input type="submit" /></td>
  83. </tr>
  84. </table>
  85. </form>
  86.  
  87. <%
  88. if ("".equals(username.trim()) && port >= 0 && "".equals(host.trim()) && "".equals(password.trim())) {
  89. %>
  90. <%
  91. return;
  92. }
  93. JSch jsch = new JSch();
  94. Session sessionJsch = null;
  95. try {
  96.  
  97. sessionJsch = jsch.getSession(username, host, port);
  98. sessionJsch.setConfig("StrictHostKeyChecking", "no");
  99. sessionJsch.setPassword(password);
  100. System.out.println("aapass: " + password);
  101. System.out.println("Establishing Connection...");
  102. sessionJsch.connect();
  103. System.out.println("Connection established.");
  104. System.out.println("Creating SFTP Channel.");
  105. Channel channel = sessionJsch.openChannel("sftp");
  106. channel.connect();
  107. ChannelSftp sftpChannel = (ChannelSftp) channel;
  108. System.out.println("SFTP Channel created.");
  109. %>
  110.  
  111. <%
  112. Vector ls = sftpChannel.ls(folder);
  113. %>
  114. <table border="1" cellpadding="1" cellspacing="3">
  115. <tr>
  116. <th>Name</th>
  117. <th>Recieved Time</th>
  118. </tr>
  119.  
  120. <%
  121. for (Object entry : ls) {
  122. ChannelSftp.LsEntry e = (ChannelSftp.LsEntry) entry;
  123. System.out.println(e.getFilename());
  124. SftpATTRS attrs = e.getAttrs();
  125. %>
  126.  
  127. <tr>
  128. <td><%=e.getFilename()%> <a
  129. href="javascript:download('<%=e.getFilename()%>')">download</a></td>
  130. <td><%=attrs.getMtimeString()%></td>
  131. <td><input type="hidden" value="form" name="form_id" /> <input
  132. type="submit" value="Download" /><a href='javascript:file()'
  133. download="<%=e.getFilename()%>">Download</a></td>
  134. </tr>
  135. <%
  136. }
  137. %>
  138.  
  139. </table>
  140. <%
  141. sftpChannel.exit();
  142.  
  143. } finally {
  144. if (sessionJsch != null) {
  145. sessionJsch.disconnect();
  146. }
  147. }
  148. %>
  149. </body>
  150. </html>
Add Comment
Please, Sign In to add comment