Is it possible to delete a file via FTP?

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

Is it possible to delete a file via FTP?

Post by amyren »

Just learning to use downloadfile and uploadfile, and I wonder if other similar functions exists.
Can I delete a file via ftp?
Or even create a directory, or upload a whole directory?

If not, perhaps this should be a post for the wishlist.

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

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

Post by plouf »

hollywood itself do not have these functions

however connecting to a passive ftp is extreme simple
and you can do it with network command
actually all FTP is simple since its one of the first ever network protocols ;-)

the following example log in and delete, as long as no problem exist (missing file / wrong password etc)

Code: Select all

SetNetworkTimeout(250)
OpenConnection(1, "127.0.0.1",21)
DebugPrint(ReceiveData(1,#RECEIVEALL))
SendData(1,"USER plouf\r")
DebugPrint(ReceiveData(1,#RECEIVEALL))
SendData(1,"PASS 123\r")
DebugPrint(ReceiveData(1,#RECEIVEALL))
SendData(1,"DELE 1.txt\r")
DebugPrint(ReceiveData(1,#RECEIVEALL))
Christos

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

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

Post by amyren »

For some reason I can not get your script to work.
The DebugPrint output is like this:
20 FTP Server ready.
23 0
0 0
0 0
0 02

I tried the same from msdos commandline, and I was able to delete the file using the same credentials and login details.
Noticing that my server will automaticly ask for username and password after opening the connection, so I dont have to use the words USER or PASS when logging in from commandline. I then tried to remove these words from the script, but no success.

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

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

Post by amyren »

I found that this will work, at least on windows systems.
Only drawback is that it will open a cmd window while the command is running

Code: Select all

StringToFile("open ftp.myserver.info\nusername\npassword\ndele file.txt\nquit", "ftp.txt")
StringToFile("ftp -s:ftp.txt", "delete.bat")
Execute("delete.bat >NIL")

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

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

Post by plouf »

you solution uses ftp internal command (ftp client) in windows os, this is a different approach :)

you output in debug shows that you successful connect to serer, but server do not react when sending USER, you have change plouf with your username but you have left \r in the end ?

also try some delay before commands
Wait(10) for example
Christos

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

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

Post by amyren »

Yes, I did leave \r at the end of each command (but I also did try without the \r)
I also tried using wait(10) and longer wait time as well.

My ftp server is hosted by hostinger, so I have now made a temporary account for you to test if you can make it work with this server.
I will send you a PM with the login details.
Edit: I see it stays in my outbox for a while now, could it be that your inbox is full?

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

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

Post by plouf »

ok helpfull

this server seems to be more STRICT and only accepts \r\n

Code: Select all

SetNetworkTimeout(2000)
OpenConnection(1, "ftp.yourftpserver.com",21)
DebugPrint(ReceiveData(1,#RECEIVEALL))
SendData(1,"USER plouf\r\n")
DebugPrint(ReceiveData(1,#RECEIVELINE))
SendData(1,"PASS 123\r\n")
DebugPrint(ReceiveData(1,#RECEIVELINE))
SendData(1,"DELE 1.txt\r\n")
DebugPrint(ReceiveData(1,#RECEIVELINE))
Christos

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

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

Post by amyren »

Got it working now. Thank you for your help.

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

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

Post by amyren »

If I may trouble you again, could you check this out as well? (I have re-enabled the ftp server for you)

I now wanted to make a directory, but it does not accept the mkdir command

Code: Select all

SendData(1, "mkdir test\r\n")
This will output "MKDIR not understood"

It looks like using senddata required a different commandset than entering it into a console. Eg DELE instead of DELETE.
mkdir, rmdir, mdelete, etc is not understood
Do you know these commands as well (or where this is explained)?

Also if I get mdelete to work, I need to know how to surpress the confirmation for each file to delete.
From the commandline I can do this by using "ftp -i", but I dont know if it is possible to add that option to OpenConnection()

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

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

Post by plouf »

Correct these vommands are not ftp. But your client ones
Makedir command in MKD

You can see raw ftp comands here
https://www.nsftools.com/tips/RawFTP.htm
Will check if not working afternoon
Christos

Post Reply