2017-05-08 104 views
2

我想用Apache Mine SSHD v1.2.0設置一個簡單的SFTP服務器。Apache Mina SFTP SftpSubsystem.Factory()

我已經看過網上的幾個例子,例如: here,herehere

但是,他們所有都有共同的行,我不能讓NetBeans來解決。 NetBeans告訴我它無法在SftpSubsystem中找到Factory。有問題的行如下:

sftpServer.setSubsystemFactories (
    Arrays. <NamedFactory <Command >> asList (new SftpSubsystem.Factory())); 

main看起來像下面這樣:

SshServer sftpServer = SshServer.setUpDefaultServer(); 
sftpServer.setPort (PORT); 
sftpServer.setKeyPairProvider (new SimpleGeneratorHostKeyProvider (new File("hostkey.ser"))); 
sftpServer.setSubsystemFactories (
    Arrays. <NamedFactory <Command >> asList (new SftpSubsystem.Factory())); 
sftpServer.setPasswordAuthenticator (new PasswordAuthenticator() { 
    @Override 
    public boolean authenticate (String username, String password, ServerSession session) { 
     return true; 
    } 
}); 
sftpServer.start(); 
while(true); 

我缺少什麼?我只是想連接到一個虛擬的SFTP服務器並列出一些目錄並上傳一兩個文件。問題是,我想從現有的Java應用程序中執行此操作。

謝謝先進。

回答

4

在最近版本的Apache SSHD的,這是SftpSubsystemFactory

sftpServer.setSubsystemFactories(
    Arrays.<NamedFactory<Command>>asList(new SftpSubsystemFactory())); 
+1

謝謝。我不知道爲什麼我找不到那個,但用你提供的那條線替換我的問題。 – AcidHawk