Home Forums .NET libraries Xceed SFTP/FTP for .NET Unable to retrieve files using Sftp

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #21510 |

    I am trying to get the files recursively from the Sftp root directory.

    With the following code:

    using (SFtpSession sftpSession = new SFtpSession(_sshClient))
                    {
                        SFtpFolder remoteFolder = new SFtpFolder(sftpSession);
                        Console.WriteLine(“Getting remote folder files “);
                        AbstractFile[] files = remoteFolder.GetFiles(true, “*.exe”);
                        foreach (AbstractFile f in files)
                        {
                            Console.WriteLine(f.FullName);
                        }
                    } 

    If I set the GetRemoteFolder to false, I can retrieve only the files present in the root directory.

    I am using Bitvise SSH trail version for now. Please let me know if I am doing it right. 

     

    Thanks 

    Applies to Xceed SFTP for .NET. Imported from legacy forums. Posted by Rahul (had 555 views)

    Diane [Xceed]
    Moderator
    Post count: 1353

    Hi Rahul,

    Yes, you are doing it right. Your code will get you the information about all the files in the remote folder.

    The ‘recursive’ Boolean parameter in GetFiles() controls whether, if true, the method looks for files in sub-folders. If false, the method only looks for files in the specified folder.

    If you wish to download the files, do the following:

       // Select a destination folder
       AbstractFolder localFolder = new DiskFolder( @”D:\SomeFolder” );

       // Copy the files in the remote folder to the local folder
       remoteFolder.CopyFilesTo( localFolder, true, true, “*.exe” );

    Applies to Xceed SFTP for .NET. Imported from legacy forums. Posted by Diane [Xceed] (had 143 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi Diane,

     Thank you for the reply. That worked for me.

     

    Applies to Xceed SFTP for .NET. Imported from legacy forums. Posted by Rahul (had 643 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.