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

Notifications

Announcements

No record found.

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
    237,878 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
    237,878 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Ali Zaidi Profile Picture

Ali Zaidi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans