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: Followup

Thanks for sharing your solution.
Though I do not understand why you are even using Session.GetFileInfo. It seems ineffective.
Just use Session.ListDirectory to get entries in /SD1 (and later its subfolders), including information whether they are files or folders.
I even better, use Session.EnumerateRemoteFiles.
jenklu

Followup

I work with arenn23. For context, the way we are using the .NET Assembly in this case is effectively equivalent to https://winscp.net/eng/docs/library_session_enumerateremotefiles. We have a recursive function that calls GetFileInfo to check if the current item was a file or directory, then recurse into the directories. The issue we faced was twofold:

  1. The Keyence FTP server advertised support for MLSD/MLST, but appeared not to work, which is why we had to switch to LIST.
  2. As Martin mentioned, the LIST implementation has to list the files in the parent of the current directory (in our case, /SD1). But since the Keyence FTP server we tried to interface with prevents access to the root directory /, the FTP server's access controls blocked this command from working

In our case, we were able to find a workaround for this issue: we simply assume the "search root" of our function is a directory and skip the GetFileInfo call on the root directory. Then, the later recursive calls only need to look at /SD1 and its subdirectories when they call LIST, which the FTP server does allow access.

Also, I just want to say thank you Martin for your support and for building such a useful WinSCP tool.
martin

Re: Could not retrieve directory listing

The GUI log shows listing of /SD1 folder contents. While the .NET assembly tries to list the root folder to obtain data about the SD1 folder (as without MLST, SIZE and MDTM commands, there's no other way).

If instead you actually want to list contents of the /SD1 folder in .NET assembly, use Session.ListDirectory, instead of Session.GetFileInfo.
https://winscp.net/eng/docs/library_session_listdirectory
arenn23

Re: Could not retrieve directory listing

Hi Martin,

We have been able to connect to the server using the WinSCP GUI. I will attach the debug logs for that session. I will also attach the .NET assembly logs without the raw MLSD setting. Is there an obvious reason why the GUI is successful but our script is not?
martin

Re: Could not retrieve directory listing

Well, then the server seem pretty much broken. It announces support for MLST, yet it then says that it doesn't know it.

WinSCP cannot provide file information, if the server has broken support for MLST command, nor supports MDTM/SIZE commands, nor listing the parent directory.
arenn23

Re: Could not retrieve directory listing

Before I set the FtpUseMlsd setting, I encountered this error:
Failed with: System.Exception: WinSCP.SessionRemoteException: Can't get attributes of file '/SD1'.

Could not retrieve file information
Unknown cmd MLST /SD1
at WinSCP.SessionLogReader.Read(LogReadFlags flags)
at WinSCP.ElementLogReader.Read(LogReadFlags flags)
at WinSCP.SessionElementLogReader.Read(LogReadFlags flags)
at WinSCP.ElementLogReader.Read(LogReadFlags flags)
at WinSCP.ElementLogReader.ReadToEnd(LogReadFlags flags)
at WinSCP.Session.DoGetFileInfo(String path)
at WinSCP.Session.GetFileInfo(String path)

I looked through other forums and thought you had suggested setting FtpUseMlsd to 1 in similar cases. However, I might have misunderstood. Unfortunately, I do not have detailed error logs for this initial case. Do you have any other suggestions for this issue?
martin

Re: Could not retrieve directory listing

I cannot tell why the server fails CWD / with "550 Unable to find /". But the reason why WinSCP even tries the CWD /, is that you disallow it from using MLST by setting FtpUseMlsd. Why are you doing that?
arenn23

Could not retrieve directory listing

Hello, I am getting the following error:
[18:22:28 ERR] Failed with: System.Exception: WinSCP.SessionRemoteException: Can't get attributes of file '/SD1'.
Could not retrieve directory listing
Unable to find /

This error occurs while utilizing the .NET assembly; the GUI seems to work. I will attach the detailed logs.