You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by im...@apache.org on 2005/10/17 20:19:38 UTC
svn commit: r325946 - in
/jakarta/commons/proper/vfs/trunk/src/examples/org/apache/commons/vfs/libcheck:
./ FtpCheck.java SftpCheck.java
Author: imario
Date: Mon Oct 17 11:19:31 2005
New Revision: 325946
URL: http://svn.apache.org/viewcvs?rev=325946&view=rev
Log:
some helpers to check used filesystem libraries
Added:
jakarta/commons/proper/vfs/trunk/src/examples/org/apache/commons/vfs/libcheck/
jakarta/commons/proper/vfs/trunk/src/examples/org/apache/commons/vfs/libcheck/FtpCheck.java (with props)
jakarta/commons/proper/vfs/trunk/src/examples/org/apache/commons/vfs/libcheck/SftpCheck.java (with props)
Added: jakarta/commons/proper/vfs/trunk/src/examples/org/apache/commons/vfs/libcheck/FtpCheck.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/examples/org/apache/commons/vfs/libcheck/FtpCheck.java?rev=325946&view=auto
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/examples/org/apache/commons/vfs/libcheck/FtpCheck.java (added)
+++ jakarta/commons/proper/vfs/trunk/src/examples/org/apache/commons/vfs/libcheck/FtpCheck.java Mon Oct 17 11:19:31 2005
@@ -0,0 +1,77 @@
+/*
+* Copyright 2003,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.vfs.libcheck;
+
+import org.apache.commons.net.ftp.FTPClient;
+import org.apache.commons.net.ftp.FTPFile;
+import org.apache.commons.net.ftp.FTPReply;
+
+/**
+ * Basic check for sftp
+ */
+public class FtpCheck
+{
+ public static void main(String args[]) throws Exception
+ {
+ if (args.length < 3)
+ {
+ throw new IllegalArgumentException("Usage: FtpCheck user pass host dir");
+ }
+ String user = args[0];
+ String pass = args[1];
+ String host = args[2];
+ String dir = null;
+ if (args.length == 4)
+ {
+ dir = args[3];
+ }
+
+ FTPClient client = new FTPClient();
+ client.connect(host);
+ int reply = client.getReplyCode();
+ if (!FTPReply.isPositiveCompletion(reply))
+ {
+ throw new IllegalArgumentException("cant connect: " + reply);
+ }
+ if (!client.login(user, pass))
+ {
+ throw new IllegalArgumentException("login failed");
+ }
+ client.enterLocalPassiveMode();
+ if (dir != null)
+ {
+ if (!client.changeWorkingDirectory(dir))
+ {
+ throw new IllegalArgumentException("change dir to '" + dir + "' failed");
+ }
+ }
+ FTPFile[] files = client.listFiles();
+ for (int i = 0; i < files.length; i++)
+ {
+ FTPFile file = files[i];
+ if (file == null)
+ {
+ System.err.println("#" + i + ": " + null);
+ }
+ else
+ {
+ System.err.println("#" + i + ": " + file.toString());
+ System.err.println("\t name:" + file.getName());
+ }
+ }
+ client.disconnect();
+ }
+}
Propchange: jakarta/commons/proper/vfs/trunk/src/examples/org/apache/commons/vfs/libcheck/FtpCheck.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/proper/vfs/trunk/src/examples/org/apache/commons/vfs/libcheck/FtpCheck.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/commons/proper/vfs/trunk/src/examples/org/apache/commons/vfs/libcheck/FtpCheck.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jakarta/commons/proper/vfs/trunk/src/examples/org/apache/commons/vfs/libcheck/SftpCheck.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/examples/org/apache/commons/vfs/libcheck/SftpCheck.java?rev=325946&view=auto
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/examples/org/apache/commons/vfs/libcheck/SftpCheck.java (added)
+++ jakarta/commons/proper/vfs/trunk/src/examples/org/apache/commons/vfs/libcheck/SftpCheck.java Mon Oct 17 11:19:31 2005
@@ -0,0 +1,92 @@
+/*
+* Copyright 2003,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.vfs.libcheck;
+
+import com.jcraft.jsch.ChannelSftp;
+import com.jcraft.jsch.JSch;
+import com.jcraft.jsch.Session;
+import com.jcraft.jsch.UserInfo;
+
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.Vector;
+
+/**
+ * Basic check for sftp
+ */
+public class SftpCheck
+{
+ public static void main(String args[]) throws Exception
+ {
+ if (args.length != 4)
+ {
+ throw new IllegalArgumentException("Usage: SftpCheck user pass host dir");
+ }
+ String user = args[0];
+ String pass = args[1];
+ String host = args[2];
+ String dir = args[3];
+
+ Properties props = new Properties();
+ props.setProperty("StrictHostKeyChecking", "false");
+ JSch jsch = new JSch();
+ Session session = jsch.getSession(user, host, 22);
+ session.setUserInfo(new UserInfo()
+ {
+ public String getPassphrase()
+ {
+ return null;
+ }
+
+ public String getPassword()
+ {
+ return null;
+ }
+
+ public boolean promptPassword(String string)
+ {
+ return false;
+ }
+
+ public boolean promptPassphrase(String string)
+ {
+ return false;
+ }
+
+ public boolean promptYesNo(String string)
+ {
+ return true;
+ }
+
+ public void showMessage(String string)
+ {
+ }
+ });
+ session.setPassword(pass);
+ session.connect();
+ ChannelSftp chan = (ChannelSftp) session.openChannel("sftp");
+ chan.connect();
+ Vector list = chan.ls(dir);
+ Iterator iterList = list.iterator();
+ while (iterList.hasNext())
+ {
+ System.err.println(iterList.next());
+ }
+ System.err.println("done");
+ chan.disconnect();
+ session.disconnect();
+ }
+}
Propchange: jakarta/commons/proper/vfs/trunk/src/examples/org/apache/commons/vfs/libcheck/SftpCheck.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/proper/vfs/trunk/src/examples/org/apache/commons/vfs/libcheck/SftpCheck.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/commons/proper/vfs/trunk/src/examples/org/apache/commons/vfs/libcheck/SftpCheck.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org