Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
4.8k views
in Java FTP by (200 points)
Hi,

I'm using v5.8 (which I understand may never be released) of the Pro library, and I'm noticing that some SFTP servers return symlinks as files. However, if I look at the raw field in the associated FTPFile, I do see the leading "l" indicating that it is a link. For now, I can easily check that first character in this case. However, I also need to make queries against the file/directory pointed to by the symlink. I noticed there is a linkedfile field, but it appears to be null, presumably because the file has not been recognized as a symlink. Also, I'm not seeing the usual "-> linked file" in the raw text in FTPFile, so I can't cheat that way. So, is there a way to resolve the fact that symlinks aren't be reported as links, or more importantly for my use case, is there a way I can determine what the link is pointing to?

Thanks,
Kevin

4 Answers

0 votes
by (51.6k points)
Hi Kevin

Firstly, FTPFile has an isLink() method that you can use to see if the entry is a symlink or not. In your case getLinkedname is probably returning null because there's no "-> linked-name" in the directory listing as there is in the following:
lrwxrwxrwx   1 wuftpd   wuftpd         14 Jul 22  2002 MIRRORS -> README-MIRRORS


Secondly, it's unfortunately not easy to see if the symlink represents a file or a directory. There's nothing in the directory listing itself to indicate what it is. This means you'd have to do some further checking to find that out. You could do that either by (1) checking to see if it's a directory by trying to change into it and then change back if you're successful, or (2) check to see if it's a file using the FTPClient.exists() method. Both of these approaches will be stymied if the FTP server has a policy of not allowing symbolic links to be followed. But then I guess it might be fairly academic what the entry actually is if you can't access it anyway.

- Hans (EnterpriseDT)
0 votes
by (200 points)
Hi Hans,

Thanks for the quick response. Unfortunately, I wasn't clear enough in my original post, so I'll try again :). Basically, I have a symlink on an SFTP server that points to a file that does exist. When I get dirDetails() on that symlink's parent directory, the FTPFile for the symlink returns false for FTPClient.isLink(). FTPClient thinks the symlink is a file and not a symlink. That's why I have to resort to reading the "raw" string to get the leading "l" character. It sounds like if the lib did see the file as a symlink, then I would be able to getLinkedNamed(), which would be great. So, any suggestions on how I might resolve the fact that the symlink is not being recognized? Really, the main thing I need at this point is to know what the symlink is pointing to.

As far as determining file vs. folder, I'm actually set there. I'm using dirDetails on the path. If that returns a single FTPFile, then it is a file. If it returns two or more (because of . and ..), then it is a directory.

Thanks for your help,
Kevin
0 votes
by (51.6k points)
Your mention of the raw format initially made me think you were talking about FTPS rather than SFTP, since that's the protocol where the raw format is used. In fact the raw property is only available in the FTPFile object when used with the SFTP protocol for legacy reasons and doesn't really have much meaning. Once we realized you really did mean SFTP, my colleague and I reviewed symbolic links in SFTP and realized that this was indeed a weak point in our implementation. We've decided how to add better support for them and will be doing so very soon. If you e-mail support then we'll let you know when symbolic link support for SFTP has been added and send you a patch.

- Hans (EnterpriseDT)
0 votes
by (51.6k points)
Note to other readers: The problems with symbolic links in SFTP were fixed to the satisfaction of Kevin (thelonius). These changes will be included with version 2.0.

- Hans (EnterpriseDT)

Categories

...