Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

Re: How to count folders recursively

OK, so does the code in my previous post help?
ssAshkea

Re: How to count folders recursively

martin wrote:

ssAshkea wrote:

I want to get all the files and folders and put them in a file

Their names/paths or contents? Please be clear!

If paths, this will do:

var filesAndDirectories = session.EnumerateRemoteFiles(directory, null, EnumerationOptions.AllDirectories | EnumerationOptions.EnumerateDirectories);

string list = string.Join(string.Empty, filesAndDirectories.Select(file => file.FullName + Environment.NewLine));
File.WriteAllText(outputFile, list);


Yes i want to get names and ways of an example:
/home/site.com/file1
/home/site.com/file2
/home/site.com/file3
martin

Re: How to count folders recursively

ssAshkea wrote:

I want to get all the files and folders and put them in a file

Their names/paths or contents? Please be clear!

If paths, this will do:

var filesAndDirectories = session.EnumerateRemoteFiles(directory, null, EnumerationOptions.AllDirectories | EnumerationOptions.EnumerateDirectories);

string list = string.Join(string.Empty, filesAndDirectories.Select(file => file.FullName + Environment.NewLine));
File.WriteAllText(outputFile, list);
ssAshkea

Re: How to count folders recursively

martin wrote:

ssAshkea wrote:

1) all the files put in the list of recursive?

I do not understand.


I want to get all the files and folders and put them in a file
martin

Re: How to count folders recursively

ssAshkea wrote:

1) all the files put in the list of recursive?

I do not understand.
ssAshkea

Re: How to count folders recursively

martin wrote:

ssAshkea wrote:

And again an error
  No overload for method 'EnumerateRemoteFiles' takes 1 arguments. "[String: 16; Column: 19]


OK, so like this: session.EnumerateRemoteFiles("/home/user/", null, EnumerationOptions.AllDirectories | EnumerationOptions.EnumerateDirectories)


Helped work.
And now how do I
1) all the files put in the list of recursive?
martin

Re: How to count folders recursively

ssAshkea wrote:

And again an error
  No overload for method 'EnumerateRemoteFiles' takes 1 arguments. "[String: 16; Column: 19]


OK, so like this: session.EnumerateRemoteFiles("/home/user/", null, EnumerationOptions.AllDirectories | EnumerationOptions.EnumerateDirectories)
ssAshkea

Re: How to count folders recursively

martin wrote:

OK, I've missed that the directory is result of session.ListDirectory is your code.

You have to pass a path as a string to the first argument of session.EnumerateRemoteFiles.

Like: session.EnumerateRemoteFiles("/home/user/")


And again an error
  No overload for method 'EnumerateRemoteFiles' takes 1 arguments. "[String: 16; Column: 19]

Now I have this code

// Setup session options

SessionOptions sessionOptions = new SessionOptions
{
    Protocol = Protocol.sftp,
    HostName = "server.com",
    UserName = "user",
    Password = "pass",
     SshHostKeyFingerprint = "ssh-rsa 2048 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:1f"
};

using (Session session = new Session())
{
   
    // Connect
    session.Open(sessionOptions);
   var directory  = session.ListDirectory("/home/user/);
   //var filesCount = session.EnumerateRemoteFiles(directory.ToString(), null, EnumerationOptions.AllDirectories);
   //var directoriesCount = session.EnumerateRemoteFiles(directory.ToString(), null, EnumerationOptions.AllDirectories | EnumerationOptions.EnumerateDirectories).Where(file => file.IsDirectory);
   
   return filesCount.Count()  ;
 
   session.Close();
}


what is wrong ?
martin

Re: How to count folders recursively

OK, I've missed that the directory is result of session.ListDirectory is your code.

You have to pass a path as a string to the first argument of session.EnumerateRemoteFiles.

Like: session.EnumerateRemoteFiles("/home/user/")
ssAshkea

ssh

What can you advise me?
And how correctly to specify a directory the absolute way is correct?
Example:
/home/user/
ssAshkea

Re: How to count folders recursively

martin wrote:

I do not know what is "kol-in folders", but this may help:

int directoriesCount =

    session.EnumerateRemoteFiles(directory, null, EnumerationOptions.AllDirectories | EnumerationOptions.EnumerateDirectories)
        .Where(file => file.IsDirectory)
        .Count();



Your method does not help produce an error

Error listing directory 'WinSCP.RemoteDirectoryInfo'.

No such file or directory.
Error code: 2
Error message from server: No such file


what to do?
ssAshkea

Re: How to count folders recursively

[quote="Anonymous"]

martin wrote:

I do not know what is "kol-in folders", but this may help:

int directoriesCount =

    session.EnumerateRemoteFiles(directory, null, EnumerationOptions.AllDirectories | EnumerationOptions.EnumerateDirectories)
        .Where(file => file.IsDirectory)
        .Count();



I apologize, I wanted to write the number of folders and files
I'll try your code, the library you have is very powerful, only my weak knowledge in C# code does not allow to open up all the potential
martin

Re: How to count folders recursively

I do not know what is "kol-in folders", but this may help:

int directoriesCount =

    session.EnumerateRemoteFiles(directory, null, EnumerationOptions.AllDirectories | EnumerationOptions.EnumerateDirectories)
        .Where(file => file.IsDirectory)
        .Count();
Guest

Who will tell?
ssAshkea

How to count folders recursively

Already the whole day I am excruciated I can not understand as to count kol-in folders of all.
Recursively

// Connect

    session.Open(sessionOptions);
   var directory  = session.ListDirectory("/admin");
   var filesCount = session.EnumerateRemoteFiles(directory.ToString(), null, EnumerationOptions.AllDirectories);
   return fileCount ;


Such code outputs such a message to the log

 WinSCP.Session+<DoEnumerateRemoteFiles>d__73