You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by manco <me...@yahoo.com> on 2005/04/23 01:30:58 UTC

commons vfs - Could not connect to SFTP server

Hi,
 
I am trying to see if I can use commons-vfs combined with JSch to connect to my
SFTP server.
 
I am using the test program from apache to verify operation before I invest too much time : public class ShowProperties
which take a uri as a command line param and just diplays stats about the file
 
I can use an ftp uri with no problems:
ftp://userX:password@hostname/home/pipe3/filename.log
/* .... */
import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSystemException;
import org.apache.commons.vfs.FileSystemManager;
import org.apache.commons.vfs.FileType;
import org.apache.commons.vfs.VFS;
import java.text.DateFormat;
import java.util.Date;
import org.apache.log4j.*;
 
public class ShowProperties
{
  private static Logger logger = Logger.getLogger( ShowProperties.class );
    public static void main(String[] args)
{ 
  ...
                FileSystemManager mgr = VFS.getManager();
                System.out.println();
                System.out.println("Parsing: " + args[i]);
                FileObject file = mgr.resolveFile(args[i]);  <----- the sftp blowup here!
...
}
I get lots of  ... "Skiping because required class not found", but I added the JSch.jar and this
eliminated the skipping msg for SFTP.
 
The following is the GOOD output from the  ftp run:
 
Parsing: ftp://userX:password@hostname/home/pipe3/filename.log
URL: ftp://userX:password@hostname/home/pipe3/filename.log
getName(): ftp://userX:password@hostname/home/pipe3/filename.log
BaseName: filename.log
Extension: log
Path: /home/pipe3/filename.log
Scheme: ftp
URI: ftp://userX:password@hostname/home/pipe3/filename.log
Root URI: ftp://userX:password@hostname/
Parent: ftp://userX:password@hostname/home/pipe3
Type: file
Exists: true
Readable: true
Writeable: true
Root path: /
Size: 1947 bytes
Last modified: 4/19/05 11:52 PM
 
The problem is when I attempt to use the SFTP, I have no problem connecting to this
host via my SSH client and with the Secure File Transfer Client.
 
I'm guessing its my uri or some other setup, any help would be appreciated,
 
Thanks,
Manco
 
ERROR Output:
 
Parsing: sftp://userX:password@hostname/home/pipe3/filename.log
 
org.apache.commons.vfs.FileSystemException: Could not connect to SFTP server at "sftp://userX:password@hostname/".
 at org.apache.commons.vfs.provider.sftp.SftpFileProvider.doCreateFileSystem(SftpFileProvider.java:86)
 at org.apache.commons.vfs.provider.AbstractOriginatingFileProvider.findFile(AbstractOriginatingFileProvider.java:76)
 at org.apache.commons.vfs.provider.AbstractOriginatingFileProvider.findFile(AbstractOriginatingFileProvider.java:61)
 at org.apache.commons.vfs.impl.DefaultFileSystemManager.resolveFile(DefaultFileSystemManager.java:505)
 at org.apache.commons.vfs.impl.DefaultFileSystemManager.resolveFile(DefaultFileSystemManager.java:483)
 at org.apache.commons.vfs.impl.DefaultFileSystemManager.resolveFile(DefaultFileSystemManager.java:453)
 at com.eMeter.vfstest.ShowProperties.main(ShowProperties.java:67)
Caused by: org.apache.commons.vfs.FileSystemException: Could not connect to SFTP server at "linuxserver1".
 at org.apache.commons.vfs.provider.sftp.SftpClientFactory.createConnection(SftpClientFactory.java:142)
 at org.apache.commons.vfs.provider.sftp.SftpFileProvider.doCreateFileSystem(SftpFileProvider.java:78)
 ... 6 more
Caused by: com.jcraft.jsch.JSchException: UnknownHostKey
 at com.jcraft.jsch.Session.checkHost(Unknown Source)
 at com.jcraft.jsch.Session.connect(Unknown Source)
 at com.jcraft.jsch.Session.connect(Unknown Source)
 at org.apache.commons.vfs.provider.sftp.SftpClientFactory.createConnection(SftpClientFactory.java:138)
 ... 7 more
 
 
 
libs being used
jsch-0.1.20
jakarta-oro-2.0.8.jar
commons-net-1.3.0.jar
commons-vfs.jar  

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Re: [VFS] Could not connect to SFTP server

Posted by Mario Ivankovits <ma...@ops.co.at>.
Hi!
> 
>Thanks "FileObject file = mgr.resolveFile(args[i], opts); " this did the trick.
>  
Great!
>1. Does VFS work for SMB file transfers?
>  
Yes, just use smb:// as scheme in your url. The required library is 
jcifs http://jcifs.samba.org/
>2. What version should I be using, are there some stable points, builds?
>  
Sorry - no, as a sandbox project there are no builds. Only nightlies for 
now.

>3. If I do a build, what do I need to do to configure ant and the properties files so that the
>    junit tests are actually run?
>  
Great question!
I finally have to start to document this process, you need a couple of 
servers to install and configure.
Stay "on list" I will post if its online.


Ciao,
Mario


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [VFS] Could not connect to SFTP server

Posted by manco <me...@yahoo.com>.
Mario,
 
Thanks "FileObject file = mgr.resolveFile(args[i], opts); " this did the trick.
 
 
I have a couple more questions:
1. Does VFS work for SMB file transfers?
2. What version should I be using, are there some stable points, builds?
3. If I do a build, what do I need to do to configure ant and the properties files so that the
    junit tests are actually run? In my previous msg I indicated that I got a successful build
    including the test classes, but the actual test target failed to do anything other than create
    the directory. It may be something I need to configure in / for the project.properties file.
 
I will check into the known_hosts issue before I fade back into the night.
A. I am currently running on a Windows XP box talking to an in-house sftp server running
    on a linux box. On windows I am running with SSH Secure Shell
B. In production I will be running on a linux box and communicating to a potentially off site 
    server, not sure if it will be linux or Windows...

 
Thanks for all your help,
Manco
 


 

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Re: [VFS] Could not connect to SFTP server

Posted by Mario Ivankovits <ma...@ops.co.at>.
manco wrote:
>1. It appears the providers.xml file in the jar  has FTPFileX.
> it doesnt seem like this is correct, I un-jarred, changed the value to FTPFile and re-jarred,
> the ftp connection now works again.
>  
Thanks - Great Hit!
Strange that this wasnt uncovered before.
>2. I dont know much about the known_hosts, but I found the following reference, which I pass
>along for the sake of others:
>  
Normally its not needet to know much about the format of the known_hosts 
file. If you use the command-line utility "ssh" to connect to a new host 
the first time it will ask you if you trust this host-key. If you answer 
"yes" it will be added to the known_hosts automatically. Though this 
could be configured through /etc/sshd/ssh_config where your 
administrator can force you to add the host-key manually.
>3. I put in the following code :
>   {
>...
>              FileSystemOptions opts = new FileSystemOptions();
>              SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(
>                 opts, "no");
>...
>                FileObject file = mgr.resolveFile(args[i]);   << still throws error
>
>       ...}
>  
You need to pass the "opts" to the resolveFile method:
FileObject file = mgr.resolveFile(args[i], opts);


Ciao,
Mario


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [VFS] Could not connect to SFTP server

Posted by manco <me...@yahoo.com>.
Update:
 
1. It appears the providers.xml file in the jar  has FTPFileX.

<provider class-name="org.apache.commons.vfs.provider.ftp.FtpFileProvider">
<scheme name="ftp"/>
<if-available class-name="org.apache.commons.net.ftp.FTPFileX"/>
</provider>

 it doesnt seem like this is correct, I un-jarred, changed the value to FTPFile and re-jarred,
 the ftp connection now works again.

2. I dont know much about the known_hosts, but I found the following reference, which I pass
along for the sake of others:

SSH_KNOWN_HOSTS FILE FORMAT
The /etc/ssh/ssh_known_hosts and $HOME/.ssh/known_hosts ...http://linux.about.com/od/commands/l/blcmdl8_sshd.htm
 
3. I put in the following code :
   {
...
              FileSystemOptions opts = new FileSystemOptions();
              SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(
                 opts, "no");
...
                FileObject file = mgr.resolveFile(args[i]);   << still throws error

       ...}
org.apache.commons.vfs.FileSystemException: Could not connect to SFTP server at "sftp://pipe:emeter@linuxserver1/".
 at org.apache.commons.vfs.provider.sftp.SftpFileProvider.doCreateFileSystem(SftpFileProvider.java:87)
 at org.apache.commons.vfs.provider.AbstractOriginatingFileProvider.findFile(AbstractOriginatingFileProvider.java:76)
 at org.apache.commons.vfs.provider.AbstractOriginatingFileProvider.findFile(AbstractOriginatingFileProvider.java:61)
 at org.apache.commons.vfs.impl.DefaultFileSystemManager.resolveFile(DefaultFileSystemManager.java:513)
 at org.apache.commons.vfs.impl.DefaultFileSystemManager.resolveFile(DefaultFileSystemManager.java:486)
 at org.apache.commons.vfs.impl.DefaultFileSystemManager.resolveFile(DefaultFileSystemManager.java:456)
 at com.eMeter.vfstest.ShowProperties.main(ShowProperties.java:88)
Caused by: org.apache.commons.vfs.FileSystemException: Could not connect to SFTP server at "linuxserver1".
 at org.apache.commons.vfs.provider.sftp.SftpClientFactory.createConnection(SftpClientFactory.java:166)
 at org.apache.commons.vfs.provider.sftp.SftpFileProvider.doCreateFileSystem(SftpFileProvider.java:79)
 ... 6 more
Caused by: com.jcraft.jsch.JSchException: UnknownHostKey
 at com.jcraft.jsch.Session.checkHost(Unknown Source)
 at com.jcraft.jsch.Session.connect(Unknown Source)
 at com.jcraft.jsch.Session.connect(Unknown Source)
 at org.apache.commons.vfs.provider.sftp.SftpClientFactory.createConnection(SftpClientFactory.java:162)
 ... 7 more

 
Q: Could this be a problem with the SFTP rejecting my connection? 
 
Thanks,
Manco

Mario Ivankovits wrote:
Hi manco!
>Caused by: com.jcraft.jsch.JSchException: UnknownHostKey
> at com.jcraft.jsch.Session.checkHost(Unknown Source)
> at com.jcraft.jsch.Session.connect(Unknown Source)
> at com.jcraft.jsch.Session.connect(Unknown Source)
> at org.apache.commons.vfs.provider.sftp.SftpClientFactory.createConnection(SftpClientFactory.java:138)
> ... 7 more
> 
The host is new for jsch or your ssh environment (known_hosts), so you 
have to trust it or pass the path to your known_hosts file to jasch

1) known_hosts
SftpFileSystemConfigBuilder.getInstance().setKnownHosts(opts, new 
File("path/to/known_hosts"));

2) or turn off the strictHostKeyChecking

FileSystemOptions opts = new FileSystemOptions();

SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, 
"no");
FileObject fo = VFS.getManager().resolveFile("sftp://xxxx", opts);

3) Or create a class which implememnts the
com.jcraft.jsch.UserInfo interface and configure it for your connection

SftpFileSystemConfigBuilder.getInstance().setUserInfo(opts, yourUserInfo);

That way you could implement a user-dialog where you ask the user to 
trust the host.


I hope one of the ways solves your problem.

---
Mario


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

		
---------------------------------
Do you Yahoo!?
 Yahoo! Small Business - Try our new resources site! 

Re: [VFS] Could not connect to SFTP server

Posted by manco <me...@yahoo.com>.
Mario,
 
Thanks for the clues, unfortunately I still cant get it to work, in fact I have taken a step back.
 
1. Is there a format for the "known_hosts" file? I tried using the format from linux/etc/hosts,
    still got the same problem.
 
2. I also tried suggestion #2, also no luck, same problem 
 
3. #3 wouldntt be the way I would be using it. I have an app that generates a bunch of files
    either another app or a thread will be running to pick up the generated files and sftp them
    off to the target, no chance for user interaction.
 
So, I tried doing a full build of vfs using the ant build.xml file. The compile build went find,
all classes and a jar were/was built, including the test classes. I thouhgt maybe I could run
the test and use the exact jars & versions as in the build. I attempted to run the 
"internal-tests" target but all it did was make the testreportdir and exit.  I see that there is 
a project.properties file, but I am not sure what I need to set to use it. 
 
So, I went back to my original test and now I can nolonger use FTP (not sftp),  for some reason, which I can not figure out I am now getting:
 
94 [main] DEBUG org.apache.commons.vfs.impl.StandardFileSystemManager  - Skipping provider "org.apache.commons.vfs.provider.ftp.FtpFileProvider" because required class "org.apache.commons.net.ftp.FTPFileX" is not available.
 
I am using JBuilder and I have commons-net in the required libs, commons-net has a FTPFile.class, I dont see anything called FTPFileX.
 
thanks,
Manco


Mario Ivankovits <ma...@ops.co.at> wrote:
Hi manco!
>Caused by: com.jcraft.jsch.JSchException: UnknownHostKey
> at com.jcraft.jsch.Session.checkHost(Unknown Source)
> at com.jcraft.jsch.Session.connect(Unknown Source)
> at com.jcraft.jsch.Session.connect(Unknown Source)
> at org.apache.commons.vfs.provider.sftp.SftpClientFactory.createConnection(SftpClientFactory.java:138)
> ... 7 more
> 
The host is new for jsch or your ssh environment (known_hosts), so you 
have to trust it or pass the path to your known_hosts file to jasch

1) known_hosts
SftpFileSystemConfigBuilder.getInstance().setKnownHosts(opts, new 
File("path/to/known_hosts"));

2) or turn off the strictHostKeyChecking

FileSystemOptions opts = new FileSystemOptions();

SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, 
"no");
FileObject fo = VFS.getManager().resolveFile("sftp://xxxx", opts);

3) Or create a class which implememnts the
com.jcraft.jsch.UserInfo interface and configure it for your connection

SftpFileSystemConfigBuilder.getInstance().setUserInfo(opts, yourUserInfo);

That way you could implement a user-dialog where you ask the user to 
trust the host.


I hope one of the ways solves your problem.

---
Mario


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Re: [VFS] Could not connect to SFTP server

Posted by Mario Ivankovits <ma...@ops.co.at>.
Hi manco!
>Caused by: com.jcraft.jsch.JSchException: UnknownHostKey
> at com.jcraft.jsch.Session.checkHost(Unknown Source)
> at com.jcraft.jsch.Session.connect(Unknown Source)
> at com.jcraft.jsch.Session.connect(Unknown Source)
> at org.apache.commons.vfs.provider.sftp.SftpClientFactory.createConnection(SftpClientFactory.java:138)
> ... 7 more
>  
The host is new for jsch or your ssh environment (known_hosts), so you 
have to trust it or pass the path to your known_hosts file to jasch

1) known_hosts
SftpFileSystemConfigBuilder.getInstance().setKnownHosts(opts, new 
File("path/to/known_hosts"));

2) or turn off the strictHostKeyChecking

        FileSystemOptions opts = new FileSystemOptions();
        
SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, 
"no");
        FileObject fo = VFS.getManager().resolveFile("sftp://xxxx", opts);

3) Or create a class which implememnts the
com.jcraft.jsch.UserInfo interface and configure it for your connection

SftpFileSystemConfigBuilder.getInstance().setUserInfo(opts, yourUserInfo);

That way you could implement a user-dialog where you ask the user to 
trust the host.


I hope one of the ways solves your problem.

---
Mario


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org