如何下载 scp 文件夹



我使用了'SCP'方法"download()"。但是,此方法是文件下载。我想知道文件夹下载...请回答我..谢谢。

//例

private boolean readFolderSCP(String localFolder, String remoteFolder)
{
   ssh.authPassword(param.getUsername(), param.getPasswd());
   File scpfile = new File(remoteFolder);
   if (scpfile.isDirectory())
   {
     String scpfiles[] = scpfile.list();
     for (int i=0; i<scpfiles.length; i++)
     {
        File remotefile = new File(remoteFolder+"/"+scpfiles[i]);
        if (remotefile.isFile())
        {
          ssh.newSCPFileTransfer().download(remoteFolder+"/"+scpfiles[i], new FileSystemFile(localFolder+"/"+scpfiles[i])); 
        } 
     }
   }    
   return true;
}

没错?

SCP并不是真正设计用来做目录列表的,因为它几乎只是一个文件复制协议。 因此,除非您确切地知道要查找的内容,否则很难从目录中获取一堆文件。

您编写的代码肯定无法获得远程目录列表,因为对new File(remoteFolder)的初始调用将查看您的本地系统,而不是远程系统。

SFTP具有与SCP相同的安全性(它基于SSH协议),并且包括FTP的所有命令,包括目录列表。 我会检查您的库文档并尝试使用 SFTP 而不是 SCP 编写您的命令。

最新更新