web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Unable to read the file name in SFTP server

(0) ShareShare
ReportReport
Posted on by 1,920

Hi All,

I need to read all the files from a folder that is available in SFTP server. I am using  Renci.SshNet.dll file.

I can able to get the number of files (total count) available in that location by using below code but unable to retrieve the name of the each file present in that location.  

SftpClient                      sftpClient;  

SftpFile                         file;    

str                                 host                = "example.com";

str                                 username       = "example";

str                                 password        = "******";       

 str remoteDirectory     = @"path\files";

sftpClient                      = new SftpClient(host, 22, username, password);

sftpClient.Connect();

 

sftpClient.ChangeDirectory('..');

str name1 = sftpClient.WorkingDirectory;

sftpClient.ChangeDirectory(remoteDirectory);

str name = sftpClient.WorkingDirectory;

 

var files = sftpClient.ListDirectory(name,null);

Please suggest on how to read the file name. 

 Thanks in advance.

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    239,660 Most Valuable Professional on at

    Can you describe the problem, please? Do you get an empty collection? Or does it throw an exception? If so, what's the type of the exception and its message? Or do you get data in the collection and you just don't know how iterate it?

  • Mohamed Meeran Profile Picture
    1,920 on at

    I faced difficulty on how to iterate it. Now i have done the same using enumerator.

    Thanks

  • Martin Dráb Profile Picture
    239,660 Most Valuable Professional on at

    Can you please share your solution with others and then mark it as the verified answer, please?

  • Lalit Jivnani Profile Picture
    395 on at

    Hello Mohamed,

    I am facing the same issue while iterating the files..
    Can you please share the code snippet which might help me in moving ahead.

    Thanks.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 21

#2
dekion Profile Picture

dekion 4

#2
Virginia99 Profile Picture

Virginia99 4

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans