B4A Library [lib] NetExtras

Here's a library i want to share with other members, original developed for forum member Biometrics.

NetExtras contains a new object FTPResume:

In order to use NetExtras you have to also include the official b4a Net library in you project.
NetExtras is based on version 1.52 of the b4a Net library.

NetExtras
Comment: NetExtras is a modified version of the official B4A Net library.
FTPResume is a modified version of the FTP Object.
It's DownloadFileResume replaces DownloadFile and it's UploadFileResume replaces UploadFile.
Both of these two new methods support resume of incomplete file download and upload.
SMTPExtras is a modified version of the SMTP object.
It has been modified to allow additional (custom) header fields to be added to the outgoing email,
and control over the connection timeout periods.
NetExtras is based on version 1.52 of the B4A Net library.
Author: B4A Net library modified by Martin Pearman
Version: 1.52
  • CustomTrustManager
    Methods:
    • Initialize (Dir As String, FileName As String)
      Initializes the trust manager based on the given cert file.
    • InitializeAcceptAll
      Initializes an "accept all" trust manager. This option should only be used in safe networks as it offers no real protection.
    • IsInitialized As Boolean
  • FTPEntry
    Methods:
    • IsInitialized As Boolean
    Properties:
    • Name As String [read only]
    • Size As Long [read only]
    • Timestamp As Long [read only]
  • FTPResume
    Events:
    • CommandCompleted (Command As String, Success As Boolean, ReplyCode As Int, ReplyString As String)
    • DeleteCompleted (ServerPath As String, Success As Boolean)
    • DownloadCompleted (ServerPath As String, Success As Boolean)
    • DownloadProgress (ServerPath As String, TotalDownloaded As Long, Total As Long)
    • ListCompleted (ServerPath As String, Success As Boolean, Folders() As FTPEntry, Files() As FTPEntry)
    • UploadCompleted (ServerPath As String, Success As Boolean)
    • UploadProgress (ServerPath As String, TotalUploaded As Long, Total As Long)
    Methods:
    • Close
      Closes the connection after all submitted tasks finish. Note that this method does not block.
    • CloseNow
      Closes the connection immediately without waiting for current tasks to finish.
      The data connection will only be closed when UploadProgress or DownloadProgress events fire.
    • DeleteFile (ServerPath As String)
      Deletes a file from the server.
      The DeleteCompleted event will be raised when this task completes.
    • DownloadFileResume (ServerFilePath As String, AsciiFile As Boolean, DeviceFolder As String, DeviceFile As String, RestartOffset As Long)
      Downloads or resumes down of a file from the server.
      The DownloadCompleted event will be raised when download completes.
      DownloadProgress events will be raised during download.
      ServerFilePath - Full path to the remote file.
      AsciiFile - If True then end of line characters will be converted as needed. Note that Android end of line character is the same as Unix / Linux.
      DeviceFolder - Folder that the file will be saved to.
      DeviceFile - The name of the local file that will be created.
      RestartOffset - The first byte to request if resuming an incomplete download. Pass 0 if you wish to download the entire file.
    • Initialize (EventName As String, Host As String, Port As Int, User As String, Password As String)
      Initializes the object and sets the subs that will handle the events
    • IsInitialized As Boolean
      Tests whether the object was initialized.
    • List (ServerPath As String)
      Fetches the list of folders and files in the specified path.
      The ListCompleted event will be raised when the data is available.
    • SendCommand (Command As String, Parameters As String)
      Sends an FTP command. The CommandCompleted event will be raised with the server reply.
      Should only be used with commands that return the reply in the command channel (not the data channel).
      It is possible that Success will be false and LastException will not be initialized.
      Common commands:
      MKD - Creates a new folder.
      RMD - Deletes an empty folder.
      Example:<code>
      FTP.SendCommand("MKD", "/somefolder/newfolder")</code>
    • SetCustomSSLTrustManager (TrustManager As Object)
    • UploadFileResume (DeviceFolder As String, DeviceFile As String, AsciiFile As Boolean, ServerFilePath As String, RestartOffset As Long)
      Uploads a file to the server.
      The UploadCompleted event will be raised when upload completes.
      UploadProgress events will be raised during the upload.
      DeviceFolder - Local folder.
      DeviceFile - Local file name.
      AsciiFile - If True then end of line characters will be converted as needed. Note that Android end of line character is the same as Unix / Linux.
      ServerFilePath - Full path to file that will be created on the server.
      RestartOffset - The first byte to send if resuming an incomplete upload. Pass 0 if you wish to upload the entire file.
    Permissions:
    • android.permission.INTERNET
    Properties:
    • PassiveMode As Boolean
      Gets or sets whether FTP is in passive mode. The default mode is active mode.
    • UseSSL As Boolean
      Gets or sets whether the connection should be done with SSL sockets (FTPS Implicit).
    • UseSSLExplicit As Boolean
      Gets or sets whether the connection should be done with SSL sockets (FTPS Explicit).
  • SMTPExtras
    Events:
    • MessageSent (Success As Boolean)
    • MessageSent2 (Success As Boolean, Tag As Object)
    Fields:
    • AUTH_CRAM_MD5 As AUTH_METHOD
    • AUTH_LOGIN As AUTH_METHOD
    • AUTH_PLAIN As AUTH_METHOD
    • Sender As String
      Gets or sets the Sender field. By default it is the same as the Username.
    Methods:
    • AddAttachment (Dir As String, FileName As String)
      Adds a file attachment.
    • AddHeader (HeaderField As String, HeaderValue As String)
      Adds a header field and header value.
    • Initialize (Server As String, Port As Int, Username As String, Password As String, EventName As String)
      Initializes the object.
      Server - Server address. Host name or Ip.
      Port - Mail server port.
      Username - Account user name.
      Password - Account password.
      EventName - The name of the sub that will handle the MessageSent event.
    • Send
      Sends the message. The MessageSent event will be raised after the message was sent.
      Note that the message fields are cleared after this method to allow you to send new messages with the same object.
    Permissions:
    • android.permission.INTERNET
    Properties:
    • AuthMethod As AUTH_METHOD
      Gets or sets the SMTP AUTH method. Default value is PLAIN.
    • BCC As List
      Gets or sets the list of "BCC" recipients.
    • Body As String
      Gets or sets the message body.
    • CC As List
      Gets or sets the list of "CC" recipients.
    • DefaultTimeout As Int [write only]
      Set the default timeout in milliseconds to use when opening a socket.
      Default value is 60000.
    • HtmlBody As Boolean
      Gets or sets whether this message body is Html text.
    • SoTimeout As Int [write only]
      Set the timeout in milliseconds of a currently open socket connection.
      Default value is 60000.
    • StartTLSMode As Boolean
      Gets or sets whether the connection should be done in StartTLS mode.
    • Subject As String
      Gets or sets the message subject.
    • Tag As Object
      Gets or Sets a Tag object for the email task to be sent.
      If a Tag object is set then the Send method will raise the event MessageSent2(Success As Boolean, Tag As Object) instead of the event MessageSent(Success As Boolean).
      A unique Tag object can therefore be used to identify which email has been sent.
    • To As List
      Gets or sets the list of "To" recipients.
      Example:<code>SMTP.To.Add("email@example.com")</code>
    • UseSSL As Boolean
      Gets or sets whether the connection should be done with SSL sockets.

So FTPResume is nearly a drop in replacement for the existing FTP object.
The differences are in the DownloadFileResume and UploadFileResume methods where a RestartOffset parameter is required.
If you pass zero as the RestartOffset parameter then the FTPResume methods will function exactly as the equivalent FTP object methods.
Otherwise the methods will begin an upload or download from the byte specified by ResumeOffset.

It is likely that the FTP server you are connecting to must support resume - if you have problems with resume check that the FTP server supports it.

I have made the version of NetExtras 1.20 to match the verison of the Net library that it modifies - there are no versions prior to 1.20.

Martin.
 

Attachments

  • NetExtras_library_files_v1.52.zip
    30.3 KB · Views: 558
Last edited:

Erel

B4X founder
Staff member
Licensed User

warwound

Expert
Licensed User
If you haven't time to solve the problem, if you can share the java source we can try to solve ourselves (and reshare the library with you).

I've attached the source code for NetExtras v1.52 (the last version i created).

Martin.
 

Q Candiani

Member
Licensed User
Hi everyone. Where can I find an exhaustive list of commands for the FTP method 'Send Command '? I need rename and move files within the FTP directory. But, however, I am interested in all commands for future cases.

Thanks
 

DonManfred

Expert
Licensed User
Top