Link to home
Start Free TrialLog in
Avatar of Pierre K
Pierre KFlag for South Africa

asked on

Delete files on FTP Server

Hi all,
I need some ideas on a possible solution please

I've got some xml files hosted on a shared server by a well known ISP

I'm trying to delete all xml files within a specific folder using a FTP Dos script since I have to do it very often (clear out old before writing new)

Tried the following:
del *.xml = Getting 550 Invalid filename error
del *.* = Getting 550 Invalid fielname error
rmdir myfolder = Getting 550 Folder not empty (if I try it from one cd level up)

So I called the ISP and they suggested
rm -rf *.xml
But it only works on their side since they have root access and I don't

Next idea might be to loop through the folder and deleting one file at a time with del filename.xml command since doing them specifically by actual filename does work via the dos script.
But I'm not sure how to loop through it using a ftp dos script? Also think the method will be slow.

Any other ideas or special switches I could use?

PS: I don't mind too much deleting and re-creating the entire folder

Thanks
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Take a look at the 'glob' command from here: http://www.nsftools.com/tips/MSFTP.htm

Do you have SSH access?  'rm -rf *.xml' is a shell command, not an FTP command.
I don't know why you are using a command FTP client.  CoreFTP http://www.coreftp.com/ has a box to select only certain files where you can put in '*.xml' and Filezilla https://filezilla-project.org/ lets you search for files with a wildcard and then select them for deletion or download.
Avatar of Pierre K

ASKER

@Dave - let me give you more info in trying to answer the SSH question

I'm a MSAccess developer so the script is running in code inside my app and therefore at each Client so I need to "automate" the process.

Here is the VBA script for more info:

f = "C:\FTPScript.txt" 'creates the file that holds the FTP commands

Open f For Output As #1
Print #1, "open ftp.mysite.co.za" 'replace ftp.server with the server address
Print #1, "myusername" 'login id here
Print #1, "mypass" 'login password here
Print #1, "cd " & " public_html" 'Directory of file location
Print #1, "cd " & " quali" 'Sub-Directory of file location
Print #1, "ascii"
Print #1, "prompt"
Print #1, "del *.xml" 'Here goes the command that needs to delete the files
Print #1, "disconnect" 'disconnect the session
'Print #1, "bye"
'Print #1, "exit"
Close #1

Shell "C:\FTP.exe -s:C:\FTPScript.txt", vbHide

Open in new window


Does that help you? Can I do the same with SHH?
WinSCP can be scripted.  Here's some info: https://winscp.net/eng/docs/guide_automation
@Dave - I'll accept your answer and close the question on your WinSCP suggestion but I will only know if and how this works after a number of days downloading, learning and testing WinSCP scripting. It would also mean having to install it at each of my existing Clients for the script to work everywhere.
Also don't know if the same problem (not having root access) to the server will crop up when trying to delete those files.
Maybe I must change ISP or pay for them to run a automated script?
Thanks again

Just giving it a bit more time for someone with a out-the-box idea before I close it ok.
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@oBdA - Tears of joy and jumping on my seat.
It had to be that simple. Full marks and thanks!
PS: There was no need to use the i-switch since there was no confirmation prompts at all
Avatar of oBdA
oBdA

Seems to be related to the ftp server; I tested it against a Microsoft FTP server, and without the -i, it prompted for every file.
On my side it would not run the code with the switch. It gave no code script errors but would not run.
So I'm so glad that I 'forgot' to add the switch in the code before testing so my initial test was with the 'mdelete' but without the switch.
If I added the 'mdelete' and the switch at the same time I might not have known that it works :)