Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetListing() generates broken FullName when used on a specific file, breaking GetFilePermissions and GetChmod #325

Closed
danieldupriest opened this issue Aug 15, 2018 · 6 comments

Comments

@danieldupriest
Copy link

danieldupriest commented Aug 15, 2018

FTP OS: Unix / Windows

FTP Server: Vsftpd

Computer OS: Windows

GetListing is sometimes used to get a single file, such as GetListing("/1234.txt"), in which case it returns an array of length 1 with the specified file. This method is used by the GetFilePermissions() and GetChmod() functions in the FluentFtp library. Unfortunately, it seems that when used in this way, GetListing generates a broken FullName for the item.

A listing for "/1234.txt" will generate an FtpListItem with the FullName of "/1234.txt/1234.txt". This breaks both GetFilePermissions() and GetChmod() functions, and I believe is also the root cause of issue #101 .

I am not certain what the fix would be, but I believe it should be easy to reproduce with some code similar to this.

FtpListItem[] good = ftpClient.GetListing("/");
foreach (FtpListItem item in good)
  Console.WriteLine("item.FullName = " + item.FullName);
FtpListItem[] broken = ftpClient.GetListing("/1234.txt");
foreach (FtpListItem item in broken)
  Console.WriteLine("item.FullName = " + item.FullName);

The FullName will be broken for the second listing.
Logs :

# GetListing("/", Auto)
Command:  TYPE I
Response: 200 Switching to Binary mode.

# OpenPassiveDataStream(AutoPassive, "LIST /", 0)
Command:  EPSV
Response: 229 Entering Extended Passive Mode (|||46928|)
Status:   Connecting to ***:46928
Command:  LIST /
Response: 150 Here comes the directory listing.
+---------------------------------------+
Listing:  -rwxrwxrwx    1 1002     1002            0 Aug 14 17:36 1234.txt
-----------------------------------------
Status:   Disposing FtpSocketStream...

# CloseDataStream()
Response: 226 Directory send OK.
Status:   Disposing FtpSocketStream...

# GetListing("/1234.txt", Auto)
Command:  TYPE I
Response: 200 Switching to Binary mode.

# OpenPassiveDataStream(AutoPassive, "LIST /1234.txt", 0)
Command:  EPSV
Response: 229 Entering Extended Passive Mode (|||29080|)
Status:   Connecting to ***:29080
Command:  LIST /1234.txt
Response: 150 Here comes the directory listing.
+---------------------------------------+
Listing:  -rwxrwxrwx    1 1002     1002            0 Aug 14 17:36 1234.txt
-----------------------------------------
Status:   Disposing FtpSocketStream...

# CloseDataStream()
Response: 226 Directory send OK.
Status:   Disposing FtpSocketStream...
@robinrodricks
Copy link
Owner

Good work finding this! I'll see what I can do..

@robinrodricks
Copy link
Owner

I think the first issue is how do you distinguish the folder paths from file paths?

@danieldupriest
Copy link
Author

My feeling is that GetListing should probably be dedicated to directories only, and a separate function provided to retrieve details of a single file, which could then be used in the GetFilePermissions and GetChmod functions.

@danieldupriest
Copy link
Author

danieldupriest commented Jul 13, 2019

Or, if you want to just try and detect which is which inside the existing function, you could go by URI guidelines, which require paths to terminate in a "/" and anything else is a file. (https://stackoverflow.com/questions/52610417/uri-for-a-directory-path-only) In that case:

/abc/abc/ is a directory listing, while

/abc/abc is a file

I don't know if this would change the current behavior of the function for your users however.

@robinrodricks
Copy link
Owner

Sorry for taking this long. We have GetObjectInfo which can be used to get the info for a single file. I checked and it supports reading the permissions as well. I have thus changed GetFilePermissions to use GetObjectInfo instead of GetListing to prevent incorrect filepaths.

Can you try and see if its fixed for you?

https://www.nuget.org/packages/FluentFTP/31.2.0

@robinrodricks
Copy link
Owner

If someone has this issue, feel free to comment and I'll reopen it. Until then I'll assume the fix worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants