NetTalk Central

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

rupertvz

  • Full Member
  • ***
  • Posts: 236
    • 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: 9106
    • 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

  • Full Member
  • ***
  • Posts: 236
    • 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: 9106
    • 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