NetTalk Central

Author Topic: Get Directory and Delete Files  (Read 4264 times)

rupertvz

  • Sr. Member
  • ****
  • Posts: 313
    • View Profile
    • Email
Get Directory and Delete Files
« on: July 10, 2018, 11:17:13 PM »
Hi Guys,

I am following the NetTalk example to download a directory (all files) from an FTP server.
It is working well ...

How do I delete the files as being downloaded?  To make sure we don't download duplicate files ...

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11158
    • View Profile
Re: Get Directory and Delete Files
« Reply #1 on: July 11, 2018, 09:14:07 PM »
use the DeleteFile(RemoteFileName) command;
http://www.capesoft.com/docs/NetTalk10/NetTalkFTP.Htm#Commands

Cheers
Bruce

rupertvz

  • Sr. Member
  • ****
  • Posts: 313
    • View Profile
    • Email
Re: Get Directory and Delete Files
« Reply #2 on: July 19, 2018, 01:05:36 AM »
Thanks Bruce,

I just need to confirm that the file was successfully downloaded, before deleting the remote-file.

Looking at the "GetNextFile" routine in the example app:

I've added the line below? (is this the correct place for adding the line)



GetNextFile Routine
  data
found  long
  code 

  loop until records (ThisFTPControl.DirListingQ) = 0
    QueueProgress += 1
    get (ThisFTPControl.DirListingQ ,1)
    If ThisFTPControl.DirListingQ.Attrib <> 0
      conversation = '-- Ignoring Not-A-file : ' & clip(ThisFTPControl.DirListingQ.Name) & '<13,10>' & Conversation
      delete (ThisFTPControl.DirListingQ)
      cycle
    end
    conversation = '-- Fetching file : ' & clip(ThisFTPControl.DirListingQ.Name) & '<13,10>' & Conversation
    ThisFTPControl.GetRemoteFile(clip (ThisFTPControl.DirListingQ.Name),clip(pParms.pLocalFileName) & '\' & ThisFTPControl.DirListingQ.Name)
    ?status{prop:text} = clip(pParms.pLocalFileName) & '\' & ThisFTPControl.DirListingQ.Name

    ThisFTPControl.DeleteFile(ThisFTPControl.DirListingQ.Name)

    delete (ThisFTPControl.DirListingQ)
    found = 1
    break
  end 

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11158
    • View Profile
Re: Get Directory and Delete Files
« Reply #3 on: July 19, 2018, 10:38:37 PM »
The GetRemoteFile command is asynchronous.
So the call there will _start_ it downloading.

Clearly you're not waiting for the result of the download, and not checking to see the file was "complete" (whatever that means), before scheduling the DeleteFile command. So the file will then be deleted regardless of the success of fail of the GetRemoteFile command.

I'd recommend inspecting the example to see where a file has been completely received, and then doing your tests, and call to DeleteFile there.

cheers
Bruce



rupertvz

  • Sr. Member
  • ****
  • Posts: 313
    • View Profile
    • Email
Re: Get Directory and Delete Files
« Reply #4 on: August 14, 2018, 02:13:00 AM »
Hi Bruce,

I am deleting the remote file as follows:

ThisFTPControl.DeleteFile(ThisFTPControl.DirListingQ.Name)

This is working, but next time I run the "GetDirectoryOverFtp" procedure, it picks up the same file name.
Which implies that the file was not initially deleted.

However, trying to the delete the file again, gives me:
"File Access Error.File Unavailable"
"No such File or Directory"
"The error number was -41 / 550 which means a general FTP error occured"


If the file was indeed deleted the first time round, why in a new thread does it pickup the same filename from the queue
"ThisFTPControl.DirListingQ.Name" ?

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11158
    • View Profile
Re: Get Directory and Delete Files
« Reply #5 on: August 14, 2018, 06:53:15 AM »
are you freeing the Queue between calls?

rupertvz

  • Sr. Member
  • ****
  • Posts: 313
    • View Profile
    • Email
Re: Get Directory and Delete Files
« Reply #6 on: August 16, 2018, 12:27:40 AM »
Hi Bruce,

I suspect the issue is related to deleting the file "too early", while the file in still in process somehow.

I am deleting the file in:

ThisFTPControl.Done PROCEDURE
After parent call

I check whether the file has been successfully saved to local disk, then delete the file.

The remote-file is successfully deleted, but the file-access error for this particular file pops up after a subsequent file is processed in the "done" procedure.

Is this the correct embed for deleting a remote file?

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11158
    • View Profile
Re: Get Directory and Delete Files
« Reply #7 on: August 16, 2018, 10:17:15 PM »
yes it's the correct embed.
I presume you wait for the DELETE to be DONE before you do the next command?

cheers
Bruce