Is it possible to delete a file via FTP?

Find quick help here to get you started with Hollywood
amyren
Posts: 204
Joined: Thu May 02, 2019 11:53 am

Re: Is it possible to delete a file via FTP?

Post by amyren »

Thanks, those commands work better:)
Now I only wonder how to use the STORE command.
I have a few hundred datafiles that I want to send to a subdir on the server. They are just a few bytes each but take long time to upload using UploadFile(). I was thinking using senddata to do it would be much faster, since it doesnt need to login for every file.

plouf
Posts: 189
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: Is it possible to delete a file via FTP?

Post by plouf »

store / retrieve / list and a few other commands are a BIT more complicated
Since they require to begin a SECOND transaction though a secondary port, where data send after you initiate them

If you just plan to upload for storing purposes, easiest imho should be to first archive them in zip, and then upload a single zip file
this have 3 advantages
1, Smaller, easier code
2, PC will be always faster in compressign than sending those files thought , sometimes slow connections.
3, less space in ftp server

hollywood zip plugin supporting opening files directly from zip files anyway

on the other hand if you plan to create a full ftp client, you have to experiment a lot :)
Christos

amyren
Posts: 204
Joined: Thu May 02, 2019 11:53 am

Re: Is it possible to delete a file via FTP?

Post by amyren »

I had a feeling that STORE could be hard to get working.
But your suggestion regarding zip is an even better solution :D Thank you.
I am not storing them as an archeive, since these files need to be individually available. But thanks to the zip plugin, I just download the zip file as a virtual file and access the files inside when needed.
The project is an online version of a bingo game I made earlier. I am making it so there will be a server and a client edition. The idea is that the person running the server create a name for the game (gamecode), and then the server will create a folder on the ftp server. The folder name is the same as the gamecode, and there all the game files are stored. Also all the .dat files (one for each available board layout), but now these are contained inside a zip file.
The client will need to know the gamecode in order to join the game, and will then download the zip file. Then as the game runs it will poll for the updated numbers log file every 3 second. This is all in a working state now.
But I am thinking about adding some sort of messaging system into this. Any suggestions on what might be the best way to do that are welcome :roll:

plouf
Posts: 189
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: Is it possible to delete a file via FTP?

Post by plouf »

yes, i have a suggestion

your idea about ftp is doable, but the most "appropriate" method is to store data in a database
database can contain anything for data / score / names to files

msu has write a PostgreSQL lib, which may be the perfetct method
offcourse you need to check a bit about SQL syntax, but its not that hard for simple stuff
and offcourse your server must have postgresql capabilites
Christos

amyren
Posts: 204
Joined: Thu May 02, 2019 11:53 am

Re: Is it possible to delete a file via FTP?

Post by amyren »

I must admit I start at zero regarding databases and sql.
But I notice that my hostinger server does have the option for me to set up a MySQL database. I need to study this some more to know how I can make that useful.

plouf
Posts: 189
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: Is it possible to delete a file via FTP?

Post by plouf »

MYSQL is diffirent than PostgreSQL,

implementing MySQL will require to write the entire database connection protocol, which is not that easy
if your host has not postgresql, better finish this project with ftp method
Christos

amyren
Posts: 204
Joined: Thu May 02, 2019 11:53 am

Re: Is it possible to delete a file via FTP?

Post by amyren »

I did make myself a draft on how I see this might be solved.
However it did involve finding a way to list files on the ftpserver in order to check for certain filetypes.
The RawFTP command LIST could probably be used to fetch a directory file list but I notice that it needs a PORT or PASV command, so this could be just as complicated as the mentioned STORE command?
I notice that I could get a folder on the server listed by https, but that would involve finding a way to strip the resulting html file for everything but the filenames.

Any idea what might be the easiest way to get such a file list from the server?

plouf
Posts: 189
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: Is it possible to delete a file via FTP?

Post by plouf »

curl (hURL plugin) can do listing but i have never understand neitehr curl not hurl ;)
Christos

amyren
Posts: 204
Joined: Thu May 02, 2019 11:53 am

Re: Is it possible to delete a file via FTP?

Post by amyren »

From the hURL docs it looks like easy:SetOpt DirListOnly could do this.
Unfortunalely there few examples in the docs on how to use this so I dont know where to start if I want to use that to get a file list from a ftp server.
Andreas, do you have any clues here?

User avatar
jPV
Posts: 383
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Is it possible to delete a file via FTP?

Post by jPV »

curl/hurl gives you a filelisting if you download a directory just like a file, it doesn't have separate functions for it. The filelisting is basically like a text file, but the nasty part is that the FTP standard doesn't define anything about the listing format, it's basically meant to be read by a human in a shell client, but hasn't been designed to be processed programmatically.

So, in the old times each system had its own format for the filelisting and you had to set the "host type" option in (graphical) FTP clients to match the server software, but nowadays the "unix standard" seems to be the most common format, and you can pretty much trust to get that with any modern FTP daemons.

In curl/hurl you can also set the DirListOnly option and then you get only names listed without any additional information, but then you can't even distinguish files from directories, so it's quite unpractical unless you know exactly what kind of files to expect.

Here's one kind of example how I'd approach the issue:

Code: Select all

@REQUIRE "hurl"

Function p_WriteStr(data$)
    tr_data$ = tr_data$ .. data$
EndFunction

Function p_HeaderData(data$)
    DebugPrint(data$)
EndFunction

Function p_Transfer(url$)
    e:SetOpt_URL(url$)
    ExitOnError(False)
    e:Perform()
    err=GetLastError()
    ExitOnError(True)
    If err
        DebugPrint(GetErrorName(err) .. " (" .. err .. ")")
    EndIf
EndFunction

Function p_GetDir(dir$)
    If Not EndsWith(dir$, "/") Then dir$ = dir$ .. "/" ; URL must end to / to get the dir listing
    e:SetOpt_WriteFunction(p_WriteStr) ; Set write function to string in the memory, instead of a file on hd or so
    tr_data$ = "" ; And clear our global string to write
    ;e:SetOpt_DirListOnly(1) ; If this is enabled, you only get file/dir names, but no other info
    p_Transfer(FullPath(addr$, dir$)) ; After this our global string has the raw unparsed dir listing
    Print(tr_data$) ; Let's just print it, but you really should parse it and return a table or something like that
EndFunction

prot$ = "ftp"
user$ = ""
pass$ = ""
port  = 21
addr$ = "main.aminet.net"

e = hurl.Easy()
e:SetOpt_Default_Protocol(prot$)
If user$ Then e:SetOpt_Username(user$) Else e:UnsetOpt_Username()
If pass$ Then e:SetOpt_Password(pass$) Else e:UnsetOpt_Password()
If port>0 Then e:SetOpt_Port(port) Else e:UnsetOpt_Port()
e:SetOpt_HeaderFunction(p_HeaderData) ; Let's print server messages on debug output
e:SetOpt_NoProgress(1) ; Let's disable the progress (meter) function

p_GetDir() ; Get the root dir listing
WaitLeftMouse
p_GetDir("comm/") ; Get a sub dir listing
WaitLeftMouse

Post Reply