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

Author Topic: Check if file exists on FTP-server  (Read 9922 times)

0 Members and 1 Guest are viewing this topic.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Check if file exists on FTP-server
« Reply #15 on: January 01, 2015, 08:00:01 pm »
This piece of code retrieves the contents of the directory and prints it on the standard output. I don't know what it is if not an example ;)
Laurent Gomila - SFML developer

Niely

  • Full Member
  • ***
  • Posts: 101
    • View Profile
Re: Check if file exists on FTP-server
« Reply #16 on: January 01, 2015, 08:24:03 pm »
Yeah, but previous times it didn't work. Really weird..

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Check if file exists on FTP-server
« Reply #17 on: January 01, 2015, 11:09:33 pm »
I did achieved this by using the rename function, and if the rename function throws an error back the file doesn't exist. :)
Ouch.

You really can't make that conclusion. The rename function may have failed (throws an error back) because you simply are not allowed to rename a file - that is, the file does exist but the FTP server does not allow you to rename it. Could also be that the file exists but the name you are trying to rename it to is not valid. You simply cannot conclude that a file does not exist just based on rename failing. Also, if rename succeeds you have now renamed the file - are you sure you want to do that?
This seems to me like a very wrong way to go about this.
Why don't you just:
 a) request a directory listing and see if the file is in the list.
 b) try to RETRieve the file and check if that succeeds.
 c) ask for the SIZE of the file and check the returned value.

See also RFC 959.
« Last Edit: January 01, 2015, 11:17:22 pm by Jesper Juhl »

 

anything