Android Tutorial [B4X] Net library (FTP, SMTP, POP) with Wait For

Status
Not open for further replies.
Starting from v1.70 of Net, jNet and iNet libraries the asynchronous methods return a 'sender filter' object.
This object can be passed as the sender filter parameter in a Wait For call.
This makes it simpler to manage multiple requests.

For example:
B4X:
'ftp was previously initialized and its event name was set to ftp:
'ftp.Initialize("ftp", "your.server", 21, "user", "password")
Dim sf As Object = ftp.UploadFile(File.DirAssets, "somefile", False, "/somefile")
Wait For (sf) ftp_UploadCompleted (ServerPath As String, Success As Boolean)
If Success Then
   Log("file was uploaded successfully")
Else
   Log("Error uploading file")
End If

Multiple subs can wait for the same event. Thanks to the sender filter parameter, each event will be intercepted in the correct wait for call.

The same technique can be used with all asynchronous methods in the Net library.

Notes

- B4i iNet and B4J jNet are internal libraries.
- B4A library is available here: https://www.b4x.com/android/forum/threads/new-net-library-android-ftp-smtp-and-pop3.10892/#content

Note that B4J and B4A libraries are identical.
 
Last edited:

Beja

Expert
Licensed User
Longtime User
This is a great function.. thanks Erel.. I remembered ProComm for DOS with Kermit protocol.. from the old good days.
 

Beja

Expert
Licensed User
Longtime User
Completely off topic but, I worked on ProComm Plus back in the late 80's - 91.

May be off topic but definitely not completely.. If you understood I meant in early nighties there was an Android function called Wait For then what can I say.
The word WaitFor rang and reminded me a similar word. and invoked memories

WaitFor "User ID"
Transmit "my ID"
WaitFor "Password"
Trasmit "xdsoh68"
WaitFor "File Name"
.
.
And so on.

I was writing this script to automate the file transmission process instead of responding to prompts one by one.
Modem: Hayes
Media: Phone line.
 
Last edited:

AHilton

Active Member
Licensed User
Longtime User
I meant that *my* comment about working for Datastorm Technologies was off topic. Not yours.
 

Beja

Expert
Licensed User
Longtime User
I meant that *my* comment about working for Datastorm Technologies was off topic. Not yours.

Hhhh understand..
Also this is off topic.. I remember I used Kermit protocol developed by Columbia university.. Other software vendors were using xmodem. When I submitted the first claims file to the insurance company, they asked me to continue using it .. It was way faster than x and y modems..
 

tufanv

Expert
Licensed User
Longtime User
Starting from v1.70 of Net, jNet and iNet libraries the asynchronous methods return a 'sender filter' object.
This object can be passed as the sender filter parameter in a Wait For call.
This makes it simpler to manage multiple requests.

For example:
B4X:
'ftp was previously initialized and its event name was set to ftp:
'ftp.Initialize("ftp", "your.server", 21, "user", "password")
Dim sf As Object = ftp.UploadFile(File.DirAssets, "somefile", False, "/somefile")
Wait For (sf) ftp_UploadCompleted (ServerPath As String, Success As Boolean)
If Success Then
   Log("file was uploaded successfully")
Else
   Log("Error uploading file")
End If

Multiple subs can wait for the same event. Thanks to the sender filter parameter, each event will be intercepted in the correct wait for call.

The same technique can be used with all asynchronous methods in the Net library.

Notes

- iNet v1.70 will be included in B4i v4.40.
this code snippet gives me an error with b4.81 with inet 1.70 :

B4X:
B4i Version: 4.81
Parsing code.    (0.03s)
Compiling code.    (0.15s)
Compiling layouts code.    (0.01s)
Compiling debugger engine code.    (1.08s)
Building Xcode project    (0.20s)
Sending data to remote compiler.    Error
B4i line: 223
Dim sf As Object = ftp.UploadFile(File.DirDocume
assigning to 'NSObject *__strong' from incompatible type 'void'

my line 223 is :
Dim sf As Object = ftp.UploadFile(File.DirDocuments, "tufan.m4a", False, "/files/tufan.m4a")

I also tried :
Dim sf As Object = ftp.UploadFile(File.DirDocuments, "tufan.m4a", False, "/files)
 

tufanv

Expert
Licensed User
Longtime User
The header file on the builder was not updated. Please try it again.
yes it compiles now thanks. Is there any way to see detailed error message because i am getting file upload error but cant find the reason , I have initilazied the ftp with my server username and password.
 

tufanv

Expert
Licensed User
Longtime User
this is the result of this:

Check Log(LastException)
B4X:
<B4IExceptionWrapper: Error Domain=caught_exception Code=0 "Error writing to stream: Error Domain=kCFErrorDomainCFNetwork Code=200 "(null)" UserInfo={kCFFTPStatusCodeKey=500, _kCFStreamErrorCodeKey=500, _kCFStreamErrorDomainKey=6}" UserInfo={NSLocalizedDescription=Error writing to stream: Error Domain=kCFErrorDomainCFNetwork Code=200 "(null)" UserInfo={kCFFTPStatusCodeKey=500, _kCFStreamErrorCodeKey=500, _kCFStreamErrorDomainKey=6}}>
 

sirac

New Member
Where to download the NET library to use ftp? I just installed B4A and it does not appear in the list of libraries to load it, greetings and thanks in advance for your help.
 

DonManfred

Expert
Licensed User
Longtime User
Where to download the NET library to use ftp?

Tip: FIRST use the forumsearch.
If you do not find what you search you can create a post. In 99% the forumsearch will find the correct thing.


 
Status
Not open for further replies.

Similar Threads

Top