Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting files from a server 2

Status
Not open for further replies.

keepingbusy

Programmer
Apr 9, 2000
1,470
GB
Hi all

Firstly, apologies if this is the wrong forum but I would be grateful for some direction where to post it if it's not.

I am trying to find out if there is a way to delete certain files from a server via phpmyadmin or some other way.

Everyday, we upload some CSV files via phpmyadmin and also upload some related images to those CSV files that contain music data. The images are the covers for the titles and all the processing and conversion is done via a Visual Foxpro 9 custom application.

As the table changes everyday, some of the images are no longer required and if not deleted, will start filling up our space.

The images are named for example 315268243789.jpg (or could be .gif), which relates to a UPC number or barcode. The list is created from the same VF9 APP (The exported file format can be adapted to any type e.g. txt, csv, tab etc).

The scenario we are trying to achieve is to create the new list (no problem), then run a piece of code that will remove the "no longer required" images from the server.

If you need any further information, please let me know.

Sorry it was long winded guys, but I hope you understand what I mean.

Many thanks
Lee

Windows XP
Visual FoxPro Version 6 & 9
 
Chris (and other visitors)

Having had much success with the deleting of files on a server, I've now taken a look at the possiblity of automating the upload of new files that are required to replace the deleted ones.

Having used the FTPPUT code, can someone please verify if the following is correct or on the right lines:
Code:
DO ftpput WITH ;
  'ourwebsitename.com', ;
  'uXXXXXXXX5', 'password', ;
  'c:\temp\20.jpg', 'test/', 2

When I run the above code, the file does not upload to the webserver folder test/ as expected.

Comparing the above with the below, have I got it the right way around or am I missing something?
Code:
Usage:
*DO ftpput WITH ;
  'ftp.host', 'name', 'password', 'source.file', ;
  'target.file'[, 1 | 2]

*:Where: lcHost     = Host computer IP address or name
*:       lcUser     = user name - anonymous may be used
*:       lcPassword = password
*:       lcSource   = source file name (remote)
*:       lcTarget   = target file name (local)
*:       lnXFerType = 1 (default) for ascii, 2 for binary

Many thanks in anticipation

Lee


Windows XP
Visual FoxPro Version 6 & 9
 
Almost. I think though, that you will either need to change to the folder named 'test/' prior to doing the upload, or change the last line to contain the entire path and filename:
Code:
'test/20.jpg'


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Lee

Untested, but you could modify your existing code as follows:-
Code:
[COLOR=blue]IF[/color][COLOR=green]
    * Existing code[/color][COLOR=blue]
ELSE
[tab]SELECT FILES2UPLOAD
[tab]SCAN
[tab][tab]IF FtpPutFile(;
[tab][tab][tab]hftpSession,;
[tab][tab][tab]ALLT(FILES2UPLOAD.COLUMN5),;
[tab][tab][tab][test/] + ALLT(FILES2UPLOAD.COLUMN5),;
[tab][tab][tab]lnXFerType,;
[tab][tab][tab]0) = 0
[tab][tab]WAIT WINDOW 'Error uploading ' + ;
[tab][tab][tab]ALLT(FILES2UPLOAD.COLUMN5) TIMEOUT 3
[tab][tab]ENDIF
[tab]ENDSCAN
ENDIF[/color]

FAQ184-2483 - answering getting answered.​
Chris [pc2]
PDFcommander.com
PDFcommander.co.uk
 
Dave

Thank you. This worked as you suggested and I was able to upload a named file:
Code:
DO ftpput WITH ;
  'ourwebsitename.com', ;
  'uXXXXXXXX5', 'password', ;
  'c:\temp\20.jpg', 'test/[b]20.jpg[/b]', 2

Chris

I looked at modifying my existing code as suggested but I'm unsure about one problem. You mentioned before about putting the SCAN.. ENDSCAN loop which works with the file deletion.

I notice that somewehere, you need to show the following:
Code:
* lcSource   = source file name (remote)
* lcTarget   = target file name (local)

I tried adding something like...
Code:
lcTarget="test/"
lcSource="c:\temp"
...in the initial PRG.

This gave me an error of variable lcTarget not found.

As Chris has previously pointed out it is much quicker to open the connection and then SCAN.. ENDSCAN etc, where do I need to add the lcTarget and lcSource variables to make this work?

The lcSource will always be at c:\temp and the target file folder will be test (for now).

Thankyou
Lee

Windows XP
Visual FoxPro Version 6 & 9
 
If you're using the code I posted in the FAQ here:
How do I transfer files using FTP?
faq184-3234


The scan would go right after the connection:
Code:
[COLOR=blue]*... SomeFile is the table and     
*... SomeField contains the file name 
USE SomeFile   [/color]
IF connect2ftp (lcHost, lcUser, lcPassword)
   WAIT WINDOW 'Transferring....' NOWAIT
   [COLOR=blue]SCAN
      STORE "C:\temp\" + SomeFile.SomeField TO lcSource 
      STORE "test/" + SomeFile.SomeField TO lcTarget
[/color]
      IF FtpPutFile(hftpSession, lcSource,;
            lcTarget, lnXFerType, 0) = 1
         WAIT WINDOW lcSource + ' transferred.' [COLOR=blue]NOWAIT    [/color]
      ENDIF
   [COLOR=blue]ENDSCAN[/color]

   = InternetCloseHandle (hftpSession)
   = InternetCloseHandle (hOpen)
ENDIF

Just call the function passing '' (nothing) in the the path parameters since you are changing them anyway:
Code:
DO ftpput WITH ;
  'ourwebsitename.com', ;
  'uXXXXXXXX5', 'password', ;
  '', '', 2


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Dave

My thanks to you for the above post and credit where it's due to your FAQ (Excellent and very useful).

This project relates to the daily updating of a music catalogue and the deletion of images for those titles and the uploading of any new ones that are in the new list.

This has become an automated process by placing a timer on the main form which allows the user to enter a time and date to start the process (This is being done in the early hours and works well).

I have a question which is probably staring me in the face, but I'll ask it anyway.

When the code runs to delete images that are no longer in the up to date list, part of the code reads:
Code:
IF FtpDeleteFile(hftpSession,[images/] + ;
  ALLT(FILEDELETE.COLUMN5)) = 0
   WAIT WINDOW 'INFO ONLY: Error deleting ' + ;
   ALLT(FILEDELETE.COLUMN5) TIMEOUT 1
ENDIF
Does the above mean that if the connection is open and the file is present on the server, it's deleted or if its not there, the WAIT WINDOW message appears.

I am trying to set up an IF, ELSE IF, ENDIF but the above appears to be between an IF and ENDIF (I hope that makes sense).

I need to delete the file from the server if it no longer applies (Thats done)
Upload any new images if it applies to the new list (Thats done)
Create a list of titles which are represented by a UPC number of any images which are not in the c:\temp folder.

If you can point me in some direction, I'm sure I can sort this out.

Thank you Dave (and Chris) for your help so far.
Lee

Windows XP
Visual FoxPro Version 6 & 9
 
You're welcome, and thanks for the positive words on the FAQ.

As for deleting a file, if you look again at the original code:
Code:
   IF FtpDeleteFile(hftpSession, lcRemoteFile) = 1
      WAIT WINDOW lcRemoteFile + ' deleted.' TIMEOUT 1
   ELSE
      WAIT WINDOW 'Error deleting ' + lcRemoteFile + "." TIMEOUT 1
   ENDIF
you'll see that in this case, a successful delete returns 1. An unsuccessful delete I believe returns 0.
Now by unsuccessful, that means it wasn't deleted. Whether it wasn't there or whether it couldn't be deleted for someother reason such as being open by another connection at the time.

This part has me confused though:
Create a list of titles which are represented by a UPC number of any images which are not in the c:\temp folder.
What do you mean there? Are you trying to get a list of files on the host that are not in your client's c:\temp folder?
If that is the case, you will need to implement an InternetFindNextFile() API call. There isn't anexample of that in the FAQ, but there is in the FTPClient download on my web site. You may want to take a look at that to get an idea of how it ticks.



-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Hi Dave

Your welcome!
What do you mean there? Are you trying to get a list of files on the host that....
That was the plan, but since updating the software, there is no need for this now as we overlooked the fact that there is another process already in place that creates a text file containing UPC numbers which is imported into another software application which in turn, extracts the images required.

Thanks again for your help for which I'm grateful.

Kind regards
Lee

Windows XP
Visual FoxPro Version 6 & 9
 
All

Can anyone shed some light on why some of our images are not being uploaded during this process?

I have run a test with the following code to ensure that firstly all the images required are present and secondly by copying them to another folder on the c: drive, it shows that they are being "found".
Code:
USE FILESTOUPLOAD
GO TOP
myes=0  &&  Used purely to count the images
SCAN
  STORE SPACE(30) TO mfilename
  STORE ALLTRIM(COLUMN7) TO mfilename
  STORE "C:\webimages\" + mfilename TO lcSource
  IF FILE(lcSource)
    myes=myes+1
    COPY FILE(lcSource) TO c:\imageupload
  ENDI
ENDSCAN
?
?LTRIM(STR(myes))
The above tells us that the images are present (2200 for this scenario) however when I run the code to upload images to the server, some files are not uploaded.

I have also tried changing the digit relating to Ascii or Binary but this has no effect.
Code:
DO ftpupload2 WITH ;
  'ourwebsite.com', ;
  'uxxxxxxxx5', 'password', ;
  '', ''
Instead of
Code:
DO ftpupload2 WITH ;
  'ourwebsite.com', ;
  'uxxxxxxxx5', 'password', ;
  '', '', [b]1[/b]
Any suggestions would be much appreciated.

(This app is written using version 9)

Thank you
Lee

Windows XP
Visual FoxPro Version 6 & 9
 
Are you absolutely sure every file is being found and copied? It looks to me like you are copying all of your files to the same file (c:\imageupload) rather than new files in that folder.
So in actuality, your copy may be failing on some files.

One anomaly of the FILE() function is that it will report .T. if the file exists anywhere the function can 'find' it, even when you provide a full path name to the function.
This includes the foxpro path, the system path, the default path,...
ADIR() is a better option.


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Hi Dave

Are you absolutely sure every file is being found and copied?

I am sure that every file exists on the lcoal drive (c:\webimages). Any files that I find are missing on the website, I check the upload folder and they are present. When these are FTP'd manually, they show on the website (Have a look at this and click on the dvd link).

In an old thread, ChrisRChamberlain mentions a software product called iIrfanview. I have checked some of the images to see if that was the problem by resizing them all to 240x240 pixels but that didn't work either.

I'm going to reduce them again and try that and also run a test by changing the webserver folder (/images) to something else to see if I can get the 2255 images uploaded and try that result.

I'll post back soon and thanks for your reply

Lee

Windows XP
Visual FoxPro Version 6 & 9
 
All

After several different tests (changing settings, file sizes etc), it's still ignoring some files to be uploaded. The files concerned are definitely present in the uploads folder but when the software runs, for some reason, it does not upload some of the images.

As mentioned, if I upload the images via FTP manually then they show.

If someone can visit the above site and do a search on touch of frost you will see on that page that some of the images are missing as an example

This is quite frustrating as I'm sure it must be a minor issue as I've a run a test with over 8000 titles with images and only a handful are missing.

Look forward to any responses guys.

Many thanks
Lee

Windows XP
Visual FoxPro Version 6 & 9
 
Hmmm. I see nine titles with nine images.

Have you been clearing your browser's cache between visits?

If you step through the code - specifically when it gets to the files that aren't uploading - do you see anything funky in the path?
Are you trapping the error number when it doesn't work?


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Hi Dave

Earlier, I cleared all the images from the server and started testing by using a table with 100 titles, then uploaded the images. That worked so I tried with 500 plus the images and that worked ok. A further test with 800 also worked.

I have just run a test with 8800 titles and when you get to about 1100 image uploads I lose the Internet connection so I'm wondering now if that's the problem.

There are no restrictions with our Internet Provider and we are using a 2mb Broadband connection.

Your thoughts would be appreciated.

Lee

Windows XP
Visual FoxPro Version 6 & 9
 
In addition to the last, the deletion of files from the server works fine with no problems and appears to run very fast. However the upload is slower but as mentioned, "cuts off" after about 1000 or so images.

Lee

Windows XP
Visual FoxPro Version 6 & 9
 
You could always try closing and reopening the connection every 100, 500 or whatever images. See if it made a difference.
Could be the host has some sort of limitation on how many files can be uploaded at a time.


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Hi Dave

Ok, that's sounds good. I'll run a test over the next few days and post back.

Just to clarify, are you talking about dividing the records into blocks of about 500 records and running the below in a DO WHILE ... ENDDO which should open and close the connection?
Code:
DO ftpupload2 WITH ;
  'ourwebsite.com', ;
  'uxxxxxxxx5', 'password', ;
  '', '', 1
Thank you for your post.

Lee

Windows XP
Visual FoxPro Version 6 & 9
 
What I had in mind was add another control structure similar to this:

USE SomeFile
DO WHILE !EOF()
STORE 0 TO nCounter
InternetOpen stuff here

SCAN REST
STORE ...... TO lcSourceFile

IF FtpPutFile...
nCounter = nCounter + 1
IF nCounter >= 500
InternetCloseHandle stuff here
EXIT &&... back to DO WHILE loop
ENDIF
ENDIF
ENDSCAN
ENDDO


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top