Topic "Session.ListDirectory does not return the current directory - Take2"

Author Message
m4rs2k
[View user's profile]

Joined: 2017-02-02
Posts: 1
Location: Montreal, Canada
*** WinSCP .NET Assembly ***

In FTP Mode, the Session.ListDirectory does not return the current directory.
Code:

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.
Code:

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 Smile
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26514
Location: Prague, Czechia
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
Advertisements

You can post new topics in this forum






Search

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License