Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

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: Session.ListDirectory does not return the current directory - Take2

The assembly does not use the concept of "working directory".
If you want to list the home directory, use the Session.HomePath.
https://winscp.net/eng/docs/library_session#homepath
m4rs2k

Session.ListDirectory does not return the current directory - Take2

*** WinSCP .NET Assembly ***

In FTP Mode, the Session.ListDirectory does not return the current directory.
using (var ftpSession = new Session())

{
    ftpSession.Open(new SessionOptions()
    {
        Protocol = Protocol.Ftp,
        HostName = "localhost",
        UserName = "test",
        Password = "Bonjour123",
    });
    var directories = ftpSession.ListDirectory(".");
    directories.Files.ToList().ForEach(x => Console.WriteLine(x.Name));
}


Output
..
File1.txt
Folder1
Folder2


However, the LIST COMMAND returns the current directory.


TELNET Example:

TELNET localhost 21
220 Hello, I'm freeFTPd 1.0
USER test
331 Password required for test
PASS Bonjour123
230 User test logged in
PASV
227 Entering passive mode (127,0,0,1,67,144)
LIST
150 Opening ASCII mode data connection
226 Directory send OK

TELNET localhost 17296 ==> 67*256+144 == 17296
drwxr-xr-x 1 root root 0 Feb 1 21:43 . <=== ** The FTP SERVER returns the current directory **
drwxr-xr-x 1 root root 0 Feb 1 21:43 ..
-rw-r--r-- 1 root root 14 Jan 26 15:42 File1.txt
drwxr-xr-x 1 root root 0 Feb 1 21:42 Folder1
drwxr-xr-x 1 root root 0 Jan 27 00:25 Folder2


- My understanding is that WinSCP or WinSCP .NET Assembly altered the result by removing the current directory entry.
- * I tried with another FTP server which does not return neither the current directory nor the parent directory. WinSCP or WinSCP .NET Assembly altered the result by adding a parent directory entry.

So my question is : Is it possible to provide a non altered result?

**********************************************************
In SFTP Mode, the Session.ListDirectory returns the current directory.
using (var sftpSession = new Session())

{
    sftpSession.Open(new SessionOptions()
    {
        Protocol = Protocol.Sftp,
        HostName = "localhost",
        UserName = "test",
        Password = "Bonjour123",
        GiveUpSecurityAndAcceptAnySshHostKey = true,

    });
    var remoteDirectories = sftpSession.ListDirectory(".");
    remoteDirectories.Files.ToList().ForEach(x => Console.WriteLine(x.Name));
}


Output
.
..
File1.txt
Folder1
Folder2

So, in this case, it works great.
* Maybe I could have some surprises with another SFTP Server.

**********************************************************
*I used the freeFTPd (FTP and SFTP) SERVER for this post.



THX :)