01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.commons.vfs.libcheck;
18:
19: import com.jcraft.jsch.ChannelSftp;
20: import com.jcraft.jsch.JSch;
21: import com.jcraft.jsch.Session;
22: import com.jcraft.jsch.UserInfo;
23:
24: import java.util.Iterator;
25: import java.util.Properties;
26: import java.util.Vector;
27:
28: /**
29: * Basic check for sftp
30: */
31: public class SftpCheck {
32: public static void main(String args[]) throws Exception {
33: if (args.length != 4) {
34: throw new IllegalArgumentException(
35: "Usage: SftpCheck user pass host dir");
36: }
37: String user = args[0];
38: String pass = args[1];
39: String host = args[2];
40: String dir = args[3];
41:
42: Properties props = new Properties();
43: props.setProperty("StrictHostKeyChecking", "false");
44: JSch jsch = new JSch();
45: Session session = jsch.getSession(user, host, 22);
46: session.setUserInfo(new UserInfo() {
47: public String getPassphrase() {
48: return null;
49: }
50:
51: public String getPassword() {
52: return null;
53: }
54:
55: public boolean promptPassword(String string) {
56: return false;
57: }
58:
59: public boolean promptPassphrase(String string) {
60: return false;
61: }
62:
63: public boolean promptYesNo(String string) {
64: return true;
65: }
66:
67: public void showMessage(String string) {
68: }
69: });
70: session.setPassword(pass);
71: session.connect();
72: ChannelSftp chan = (ChannelSftp) session.openChannel("sftp");
73: chan.connect();
74: Vector list = chan.ls(dir);
75: Iterator iterList = list.iterator();
76: while (iterList.hasNext()) {
77: System.err.println(iterList.next());
78: }
79: System.err.println("done");
80: chan.disconnect();
81: session.disconnect();
82: }
83: }
|