Android Question Upload multiple files to FTP

Setlodi

Active Member
Hi there

I am able to upload a single file to FTP. However, I need help uploading multiple files with the .pdf extension. Any ideas?

Thanks in advance.
 
Solution
1. You are closing FTP after the first file.
2. You can use For Each, which is more elegant.
Code:
FTP.PassiveMode = True
For Each pdfFile In pdfList
 If pdfFiles.EndsWith(".pdf") Then 
            Dim sf As Object =    FTP.UploadFile(File.DirInternal, pdfFiles, False, "/Test_Folder/" & pdfFiles)
            Wait For (sf) FTP_UploadCompleted (ServerPath As String, Success As Boolean)
            Log(ServerPath & ": "&  Success)
 End If
Next
FTP.Close
I'm now experiencing a problem that I can't seem to solve...

When I run my app without Wait for... it copies all files to the FTP

[CODE lang="b4x" title="Without Wait For..."] Dim pdfList As List
Dim i As Int
pdfList.Initialize
pdfList=File.ListFiles(File.DirInternal)
For i=0 To pdfList.Size-1
pdfFiles=pdfList.Get(i)
If pdfFiles.EndsWith(".pdf")
FTP.PassiveMode = True
FTP.UploadFile(File.DirInternal, pdfFiles, False, "/Test_Folder/" & pdfFiles)
FTP.Close
End If
Next[/CODE]

However, when I include Wait for... only the first file is copied

[CODE lang="b4x" title="Including Wait For..."] Dim pdfList As List
Dim i As Int
pdfList.Initialize
pdfList=File.ListFiles(File.DirInternal)
For i=0 To pdfList.Size-1
pdfFiles=pdfList.Get(i)
If pdfFiles.EndsWith(".pdf") Then
FTP.PassiveMode = True
Dim sf As Object = FTP.UploadFile(File.DirInternal, pdfFiles, False, "/Test_Folder/" & pdfFiles)
Wait For (sf) FTP_UploadCompleted (ServerPath As String, Success As Boolean)
FTP.Close
End If
Next[/CODE]

What am I doing wrong...?

Events...

[CODE lang="b4x" title="Events"]Sub FTP_UploadProgress (ServerPath As String, TotalUploaded As Long, Total As Long)
Dim s As String
s = "Uploaded " & Round(TotalUploaded / 1000) & "KB"
If Total > 0 Then s = s & " out of " & Round(Total / 1000) & "KB"
Log(s)
End Sub
Sub FTP_UploadCompleted (ServerPath As String, Success As Boolean)
Log(ServerPath & ", Success=" & Success)
If Success = True Then
Log("COPIED")
Else
Log(LastException.Message)
End If
End Sub[/CODE]
 
Upvote 0
1. You are closing FTP after the first file.
2. You can use For Each, which is more elegant.
Code:
FTP.PassiveMode = True
For Each pdfFile In pdfList
 If pdfFiles.EndsWith(".pdf") Then 
            Dim sf As Object =    FTP.UploadFile(File.DirInternal, pdfFiles, False, "/Test_Folder/" & pdfFiles)
            Wait For (sf) FTP_UploadCompleted (ServerPath As String, Success As Boolean)
            Log(ServerPath & ": "&  Success)
 End If
Next
FTP.Close
 
Upvote 0
Solution
Back
Top