Upload all images in a folder to FTP and Verify upload was successful.

arr0ba

Member
Licensed User
Longtime User
I am sending all the files in the .temp to an ftp, I want to verify the file actually made it before I delete it from the device so that it does not get transmitted twice. How would I go about doing that? I am currently running a beta and the user tells me he did it right, and yet I receive nothing and when I check the queue .temp folder there's nothing in there.. So I must have my code wrong and probably deleting the files even thought they never made it to the server. Here is my code, if you have better code for transmiting all the images in one folder and verified the upload please share...

Thank you,:sign0085:

B4X:
Sub PostAllFiles As Boolean
Dim MyList As List
 MyList.Initialize        'initialize list so it is ready for a new task            
    Dim MyFile As String
    MyList=File.ListFiles(File.DirRootExternal & "/.temp/")
    For i=0 To MyList.Size-1
           MyFile=MyList.Get(i)
PostFile(File.DirRootExternal & "/.temp/",MyFile)
Next
Return True
UploadInProgress = False
End Sub

Sub PostFile(Dirstr As String,Filestr As String) 
'Add files
FTP.UploadFile(Dirstr, Filestr,False, "/" & Filestr)
FTP.CloseNow
End Sub

Sub FTP_UploadCompleted (ServerPath As String, Success As Boolean)
Log(ServerPath & ", Success=" & Success)
If Success = True Then
File.Delete(File.DirRootExternal & "/.temp",ServerPath)
End If
If Success = False Then Log(LastException.Message)
End Sub
 

mc73

Well-Known Member
Licensed User
Longtime User
I think you should remove the ftp.closeNow. As it name suggests, you immediately close the connection with the server, thus no file should be uploaded. At least, so I understand this command. You should close the ftp, in the ftp_uploadCompleted sub if you have to.
 
Upvote 0
Top