Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%@page import="java.util.Collections"%>
- <%@page import="org.apache.commons.io.*"%>
- <%@page import="java.io.File"%>
- <%@page import="java.io.File"%>
- <%@page import="com.jcraft.jsch.*"%>
- <%@page import="java.util.Vector"%>
- <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
- pageEncoding="ISO-8859-1"%>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
- <title>Insert title here</title>
- </head>
- <script>
- function download(fn) {
- alert("downloading: " + fn);
- }
- </script>
- <body>
- <%
- String filname;
- String username = request.getParameter("username");
- if (null == username)
- username = "";
- String password = request.getParameter("password");
- if (null == password)
- password = "";
- String host = request.getParameter("host");
- if (null == host) {
- host = "";
- }
- String portStr = request.getParameter("port");
- if (null == portStr)
- portStr = "";
- int port = 0;
- try {
- port = Integer.parseInt(portStr);
- } catch (Exception ex) {
- }
- String folder = request.getParameter("folder");
- if (null == folder) {
- folder = "";
- String download = request.getParameter("dwnld");
- boolean flag = false;
- if (download != null) {
- flag = true;
- }
- }
- %>
- <form method="POST">
- <table>
- <tr>
- <th align="right">SFTPHOST</th>
- <td><input name="host" value=<%=host%> size="50" type="text"></td>
- </tr>
- <tr>
- <th align="right">Username</th>
- <td><input name="username" value="<%=username%>"></td>
- </tr>
- <tr>
- <th align="right">Password</th>
- <td><input name="password" value="<%=password%>"
- type="password"></td>
- </tr>
- <tr>
- <th>Port</th>
- <td><input type="number" name="port" size="4" value="<%=port%>" /></td>
- </tr>
- <tr>
- <th>Working Directory</th>
- <td><input name="folder" value="<%=folder%>" size="100" /></td>
- </tr>
- <p style="color: red">Please provide full path</p>
- <tr>
- <td colspan="2"><input type="submit" /></td>
- </tr>
- </table>
- </form>
- <%
- if ("".equals(username.trim()) && port >= 0 && "".equals(host.trim()) && "".equals(password.trim())) {
- %>
- <%
- return;
- }
- JSch jsch = new JSch();
- Session sessionJsch = null;
- try {
- sessionJsch = jsch.getSession(username, host, port);
- sessionJsch.setConfig("StrictHostKeyChecking", "no");
- sessionJsch.setPassword(password);
- System.out.println("aapass: " + password);
- System.out.println("Establishing Connection...");
- sessionJsch.connect();
- System.out.println("Connection established.");
- System.out.println("Creating SFTP Channel.");
- Channel channel = sessionJsch.openChannel("sftp");
- channel.connect();
- ChannelSftp sftpChannel = (ChannelSftp) channel;
- System.out.println("SFTP Channel created.");
- %>
- <%
- Vector ls = sftpChannel.ls(folder);
- %>
- <table border="1" cellpadding="1" cellspacing="3">
- <tr>
- <th>Name</th>
- <th>Recieved Time</th>
- </tr>
- <%
- for (Object entry : ls) {
- ChannelSftp.LsEntry e = (ChannelSftp.LsEntry) entry;
- System.out.println(e.getFilename());
- SftpATTRS attrs = e.getAttrs();
- %>
- <tr>
- <td><%=e.getFilename()%> <a
- href="javascript:download('<%=e.getFilename()%>')">download</a></td>
- <td><%=attrs.getMtimeString()%></td>
- <td><input type="hidden" value="form" name="form_id" /> <input
- type="submit" value="Download" /><a href='javascript:file()'
- download="<%=e.getFilename()%>">Download</a></td>
- </tr>
- <%
- }
- %>
- </table>
- <%
- sftpChannel.exit();
- } finally {
- if (sessionJsch != null) {
- sessionJsch.disconnect();
- }
- }
- %>
- </body>
- </html>
Add Comment
Please, Sign In to add comment