PxPlus User Forum
Main Board => Discussions => Programming => Topic started by: Mike Hatfield on June 05, 2019, 08:34:11 PM
-
Hi All,
We have written our code to access a Magento FTP Server using CURL to download orders from a folder in json format.
To avoid processing the same orders I need to remove the file from the Magento FTP server as we process it.
That remove command structure is eluding me.
Has anyone removed a file from an FTP Server?
Thanks
-
cURL doesn't support FTP delete directly but it does allow you to execute FTP commands manually. To delete you can send a FTP delete command manually using cuRL.
-Q -DELE /path/to/filetodelete
-
Hi Devon,
I tried your suggestion
F:\HIT\TEMP\FTPFILES>curl -k --ssl -Q -DELE ftp://ftp.servername.com.au/public_html/Future/Texts/filename.txt --user username@servername.com.au:password
This is what came back
052C10398880632B4914768747600603C351BF179135309830EE638478376AFA
curl: (21) QUOT string not accepted: DELE
21 FTP quote error. A quote command returned error from the server.
-
I missed the quotes and the URL and the delete command are separate. Try this:
curl -k -ssl --user username@servername.com.au:password ftp://ftp.servername.com.au/public_html/Future/Texts/ -Q "-DELE filename.txt"
-
Hi Devon,
I thought it was going to work but sadly not....
The CURL command seems to be accepted but it just hangs and eventually it times out
curl -k --ssl --user username@servername.com.au:password ftp://ftp.servername.com.au/public_html/Future/Texts/ -Q " -DELE filename.txt"
curl: (28) Timeout was reached
I don't think its the directory (0755) file permissions (0744) because curl didn't complain
-
Our FTP utility uses a command like that to do deletes so as far as I known it should work.
Maybe try getting rid of the space before the -DELE
Maybe try moving the path from the server URL to in front of the filename
If those suggestions don't work you may want to try curl support as this is now strictly a curl question.
-
Removing the space certainly made a difference.
It now produces a directory listing on the command window but doesn't delete anything.
That's because the ftp url ends with /Texts/ which generates a listing.
So it seems the -Q onwards was ignored.
As you say, time to consult with curl support.
Thanks for trying.
-
This worked!
-O or -o is needed depending on whether you want to download to other than the current folder
curl -k -ssl --user username@servername.com.au:password -o \hit\somefolder\Magento\Orders\filename.txt ftp://ftp.servername.com.au/public_html/Future/Texts/ -Q "-DELE filename.txt"
I had to be patient though.
It appeared the file wasn't deleting whilst monitoring the ftp server with Filezilla.
It just takes a while to refresh.
-
Mike,
I recently ran into a hosted ftp curl delete issue and the answer was to put a ./ before the filepath.