1

SharpSsh を使用して、サーバーから SFTP にファイルを再帰的にダウンロードする必要があります。しかし、ファイル名またはディレクトリを特定する方法がわかりません。今はそうしています

 static void recDir(string remotePath, string localPath)
 {
     Sftp _c = this.sftp;
     ArrayList FileList = _c.GetFileList(remotePath);
     FileList.Remove(".");
     FileList.Remove("..");
     for (int i = 0; i < FileList.Count; i++)
     {
         try
         {
             _c.Get(remotePath + "/" + FileList[i], localPath + "/" + FileList[i]);

             Console.WriteLine("File: " + remotePath + "/" + FileList[i]);
         }
         catch (Exception e)
         {
             Console.WriteLine("Dir: " + remotePath + "/" + FileList[i]);
                System.IO.Directory.CreateDirectory(localPath + "/" + FileList[i]);
                recDir(remotePath + "/" + FileList[i], localPath + "/" + FileList[i]);
         }
     }
 }

動作しますが、正しくないようです。

4

1 に答える 1

2

SharpSSH API はそれを許可しません。ただし、SharpSSH はオープン ソースであるため、コーディングできます。ただし、SharpSSH は適切な選択ではないことに注意してください。何年も維持されていません。


別の同様の SharpSSH の質問に対する私の回答を参照してください。

または、別の SFTP ライブラリを使用します。

  • SSH.NETにはSftpClient.ListDirectoryIEnumerable<SftpFile>. はプロパティSftpFileを持っています.IsDirectory
  • WinSCP .NET アセンブリには、 with プロパティのコレクションをSession.ListDirectory( 経由で) 返すメソッドがあります(私は WinSCP .NET アセンブリの作成者です)。RemoteDirectoryInfo.FilesRemoteFileInfo.IsDirectory
于 2015-03-09T08:16:20.467 に答える