SFML community forums

Help => Network => Topic started by: vEjEsE on March 25, 2014, 05:57:26 pm

Title: FTP: find out if it's a file or a folder
Post by: vEjEsE on March 25, 2014, 05:57:26 pm
Hello,

Is there any way to find out if a path is directory or file?
The only way I figured is to try and changeDirectory() into every item of the listing returned, if it doesn't work, it's a file.

Is there any other, more applicable, check I could do?

Checking for a .extension of the string won't always work, folders can have dots, files may not have dots.
Title: Re: FTP: find out if it's a file or a folder
Post by: dabbertorres on March 25, 2014, 06:42:59 pm
You could look into using <dirent.h>. I've used it for scanning directories for files and other directories. It's a plus, as it works on Windows and Linux, and I believe it works on OSX.

It's a C header, so you gotta deal with that if you haven't before, but it's not too difficult. If you decide to go that route and need pointers (pun intended), I can help with that.

Oops, sorry, I misunderstood. Won't work obviously.
Title: Re: FTP: find out if it's a file or a folder
Post by: vEjEsE on March 25, 2014, 07:10:43 pm
Not at a PC now.

Quick question:
All I have is the sf::Ftp interface for the files on the remote server, and all it returns is sf::Ftp::Reponse.
How could I use the lib with that?
Title: Re: FTP: find out if it's a file or a folder
Post by: Laurent on March 25, 2014, 07:42:49 pm
Of course you can't use any file system lib since you work on the remote FTP server. All you have is a bunch of FTP commands.

Unfortunately I don't think there is a command that clearly gives this information. As far as I know, FTP clients parse the non-standard information given by a command that returns information about files/folders (don't remember which one it is) to find if they are files or folders.
Title: Re: FTP: find out if it's a file or a folder
Post by: binary1248 on March 25, 2014, 09:00:29 pm
Unfortunately I don't think there is a command that clearly gives this information. As far as I know, FTP clients parse the non-standard information given by a command that returns information about files/folders (don't remember which one it is) to find if they are files or folders.
Which is why the IETF proposed RFC 3659 (http://tools.ietf.org/html/rfc3659). I think the abstract speaks for itself:
Code: [Select]
   This document specifies new FTP commands to obtain listings of remote
   directories in a defined format, and to permit restarts of
   interrupted data transfers in STREAM mode.  It allows character sets
   other than US-ASCII, and also defines an optional virtual file
   storage structure.
The command which would be useful in this scenario would be MLSD (http://tools.ietf.org/html/rfc3659#section-7). Don't ask me how many FTP servers have already implemented this. We all know how administrators live under a rock and only come out when things break ;).
Title: Re: FTP: find out if it's a file or a folder
Post by: vEjEsE on March 26, 2014, 12:14:07 am
I need to send a command to the server that gives me information that I shouldn't trust about whether it's a file or a folder.

How do FTP managers do it?

For sending a command to the server, can I extend the sf::Ftp class in order to add a "sendCommand" method?
Title: Re: FTP: find out if it's a file or a folder
Post by: vEjEsE on March 28, 2014, 09:18:15 am
Yes, why, yes it works.
I just have to use the "sendCommand" method. But it's private (why?).
Need to inherit in a weird manner.

Command:
NLST  -  Returns a list of file names in a specified directory.
Would help? Are directory considered files?
Title: Re: FTP: find out if it's a file or a folder
Post by: vEjEsE on March 28, 2014, 12:03:03 pm
Wait, I can't get access to private method with inheritance. What was I talking about?

Would making "sendCommand" method protected be a bad suggestion?
Title: Re: FTP: find out if it's a file or a folder
Post by: Laurent on March 28, 2014, 12:22:42 pm
Quote
Would making "sendCommand" method protected be a bad suggestion?
It should even be public ;)
Title: Re: FTP: find out if it's a file or a folder
Post by: vEjEsE on March 28, 2014, 12:28:00 pm
Where do I submit that? Github?

For now, if I modify the header file (SFML/Network/Ftp.hpp) and move the method into public scope, would that be a bad idea?
Title: Re: FTP: find out if it's a file or a folder
Post by: Nexus on March 28, 2014, 01:40:58 pm
Where do I submit that? Github?
In general, pull requests can be submitted on GitHub, yes.

But for things that are so tiny that they can be fixed within a matter of few minutes, the pull request overhead (commit, submit, review, edit, merge) is not worth the effort.

It's fixed now ;)
Title: Re: FTP: find out if it's a file or a folder
Post by: vEjEsE on March 29, 2014, 01:00:28 am
Yes, that makes sense. Thank you.

Last quick question:
Is SFML nightly build stable enough to use it in learning?
Title: Re: FTP: find out if it's a file or a folder
Post by: Nexus on March 29, 2014, 11:09:16 am
The nightly builds are quite outdated, I recommend using the latest Git revision. Especially because you want sf::Ftp::sendCommand() to be public, which I implemented only yesterday.