Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: FTP: find out if it's a file or a folder  (Read 4249 times)

0 Members and 1 Guest are viewing this topic.

vEjEsE

  • Newbie
  • *
  • Posts: 28
    • View Profile
FTP: find out if it's a file or a folder
« 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.

dabbertorres

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • website/blog
Re: FTP: find out if it's a file or a folder
« Reply #1 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.
« Last Edit: March 25, 2014, 08:22:07 pm by dabbertorres »

vEjEsE

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: FTP: find out if it's a file or a folder
« Reply #2 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: FTP: find out if it's a file or a folder
« Reply #3 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.
Laurent Gomila - SFML developer

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: FTP: find out if it's a file or a folder
« Reply #4 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. 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. 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 ;).
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

vEjEsE

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: FTP: find out if it's a file or a folder
« Reply #5 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?

vEjEsE

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: FTP: find out if it's a file or a folder
« Reply #6 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?

vEjEsE

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: FTP: find out if it's a file or a folder
« Reply #7 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: FTP: find out if it's a file or a folder
« Reply #8 on: March 28, 2014, 12:22:42 pm »
Quote
Would making "sendCommand" method protected be a bad suggestion?
It should even be public ;)
Laurent Gomila - SFML developer

vEjEsE

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: FTP: find out if it's a file or a folder
« Reply #9 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?
« Last Edit: March 28, 2014, 12:52:23 pm by vEjEsE »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: FTP: find out if it's a file or a folder
« Reply #10 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 ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

vEjEsE

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: FTP: find out if it's a file or a folder
« Reply #11 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?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: FTP: find out if it's a file or a folder
« Reply #12 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: