#Region  Project Attributes 
	#ApplicationLabel: B4A Example
	#VersionCode: 1
	#VersionName: 
	'SupportedOrientations possible values: unspecified, landscape or portrait.
	#SupportedOrientations: unspecified
	#CanInstallToExternalStorage: False
	#BridgeLogger: True 
#End Region

#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: True
#End Region

Sub Process_Globals
	Dim FTP As FTP
	Dim CC As ContentChooser
	Dim Dirr As String
	Dim FileN As String
End  Sub
Sub Globals

End  Sub

Sub Activity_Create(FirstTime As  Boolean )
	Activity.LoadLayout("Layout")
	CC.Initialize("CC")
    
	If FirstTime Then
		' FTP.Initialize("FTP", "mydomain.com", 21, "myname", "mypassword")
		FTP.Initialize( "FTP" , "192.168.18.117" , 21, "User1" , "123" )
		FTP.PassiveMode= True
		FTP.UseSSL = False
		FTP.UseSSLExplicit = False
	End  If
End  Sub

' Download ********************************* 
Sub Button1_Click
	' Download
	FTP.DownloadFile( "/Test.txt" , False ,Dirr, "Test.txt" )
End  Sub

Sub FTP_DownloadProgress (ServerPath As  String , TotalDownloaded As  Long , Total As  Long )
	Dim s As  String
	s = "Downloaded " & Round(TotalDownloaded / 1000) & "KB"
	If Total > 0 Then s = s & " out of " & Round (Total / 1000) & "KB"
	Log(s)
End  Sub
' End of Download 
Sub FTP_DownloadCompleted (ServerPath As  String , Success As  Boolean )
	Log(ServerPath & ", Success=" & Success)
	If Success = False  Then Log(LastException.Message)
End  Sub

' Upload ********************************* 
Sub Button2_Click
	' Upload
	CC.Show("text/*", "Choose Text")
    Log(Dirr)
	FTP.UploadFile(Dirr, "Test.txt" , True , "/Test.txt" )
End  Sub

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
' End 
Sub FTP_UploadCompleted (ServerPath As  String , Success As  Boolean )
	Log(ServerPath & ", Success=" & Success)
	If Success = False  Then Log(LastException.Message)
End  Sub

' List ********************************* 
Sub Button3_Click
	' List
	FTP.List( "./" )
End  Sub
' End of list 
Sub FTP_ListCompleted (ServerPath As  String , Success As  Boolean , Folders() As FTPEntry, Files() As FTPEntry)
	Log(ServerPath)
	If Success = False  Then
		Log(LastException)
	Else
		For i = 0 To Folders.Length - 1
			Log(Folders(i).Name)
		Next
		For i = 0 To Files.Length - 1
			Log(Files(i).Name & ", " & Files(i).Size & ", " & DateTime. Date (Files(i).Timestamp))
		Next
	End  If
End  Sub
' Close connection 
'Sub Button4_Click
'	FTP.Close
'End Sub


Private Sub Button5_Click
	CC.Show("text/*", "Choose Text")
	
End Sub

Sub CC_Result (Success As Boolean, Dir As String, FileName As String)
	
	If Success = True Then
'		ImageView1.Bitmap = LoadBitmap(Dir,FileName)
		ToastMessageShow("Uploaded ",True)
		ToastMessageShow(Dir,True)
		ToastMessageShow(FileName,True)
		
		
	Else
		ToastMessageShow("No Success :(",True)
	End If
	Dirr =Dir
	FileN=FileName
		
End Sub