B4A Library Tiny FTP Server as Class

Hello,
I created a tiny FTP server implemented as a class to use in B4A apps. The source and an example project is attached.

Why ???

Several of my projects allow the user to add files containing a word list or database records to the app's directory. These are imported and used within the app. Currently I tell people install a third-party FTP, connect using a client on a PC, navigate to my app's directory, and transfer the file. That seems to be a little too much to ask.

Embedding the tiny FTP server into an app allows the user to invoke the FTP using a button or menu item within the app, connect from a PC, and transfer the file directly to the proper directory. Maybe this will be a little easier.

The tiny FTP server is limited in that you cannot change your working directory and I have not implemented all the FTP commands.

At the bottom of the TinyFTPSvr.bas file there are a couple handy utilities: Sprintf - similar to the C function, and FormatDateTime - similar to the Delphi function.

For convenience I have included in the attached zip file the set of utilities, DateUtils.bas, created by Erel.

Barry.
 

Attachments

  • MyFTP.zip
    38.5 KB · Views: 411
Last edited:

Rusty

Well-Known Member
Licensed User
Thanks for the post.
I tried to compile it and it complains in the TinyFTPSvr code. It can't resolve
B4X:
Dim fs as MLfiles
There doesn't seem to be a definition of MLfiles.
Can you explain?
Thanks
Rusty
 

canalrun

Well-Known Member
Licensed User
Thanks for the post.
I tried to compile it and it complains in the TinyFTPSvr code. It can't resolve
B4X:
Dim fs as MLfiles
There doesn't seem to be a definition of MLfiles.
Can you explain?
Thanks
Rusty

Sorry. It looks like I used several third-party libraries from my additional libraries folder without stating this.

The additional libraries I have used and have included in the "Referenced Libraries" are:

ByteConverter - from agraham, http://www.basic4ppc.com/forum/addi...tes/6787-byteconverter-library.html#post39339

MLfiles - from HotShoe, http://www.basic4ppc.com/forum/addi...19247-file-handling-library-2.html#post110861

I have located these in my "Additional libraries" B4A directory.

Barry.
 

GMan

Well-Known Member
Licensed User
I wanted to use this samples for an own ftp-server, but even the sample didnt work.

If i start MyFTP, the files are listed.
If i click Open FTP it opens the server
if i connect with a ftp-clientUSER and USER are accepted and in the LOG-File area of B4A the files are shown

BUT not in the FTP-Client window....?

Who knows what's wrong ?

P.S.:i noticed the following: if i let my ftp-client "connected" (didnt cancel the job) the content of the external foler is shown in exactly that moment, when b4a is ready with the transfer of a new compilation !
 
Last edited:

GMan

Well-Known Member
Licensed User
OK, found the reason:
i am developing on an "old" Touchlet with 2.3 - may be this would cause the problem ?

I i run the app on a Quad Core Device the file list is shown at once...but: why does it not work on the "old" device ?
 

canalrun

Well-Known Member
Licensed User
OK, found the reason:
i am developing on an "old" Touchlet with 2.3 - may be this would cause the problem ?

I i run the app on a Quad Core Device the file list is shown at once...but: why does it not work on the "old" device ?


Good Catch!

I developed this testing on two Android 3.0 and higher devices. I just tried it on an older Android 2.3 device and I got the same results as you.

I will look into this further, but my guess is that the older operating system does not return the same result from some function call. I notice on both the older and newer devices the MyFTP program performs the same operations (the response to the FTP LIST command shown in the device window is a directory listing).

Barry.
 

GMan

Well-Known Member
Licensed User
In the log list of the client is written that it also send LIST.

As written: if i let the connection "open" and transfer the app again via wireless (same ip: B4A and FTP) in JUST THIS moment the result is shown.

Seems it "hooks" somewhre and waits for an (additional) command ?
Other apps like FTPdroid works well and works on the same device.
 

RaymondHung

Member
Licensed User
Hi canalrun

I tried to upload some movie files, some image shows grid when playing.
But other FTP server app, do not have such problem. Do you know why?

Thanks
 

canalrun

Well-Known Member
Licensed User
Thanks for any suggestions!

Hello,
Sorry I did not reply sooner. I will have to mark this thread as "watched" so I am alerted if there are any posts.

If I understand the question correctly…

When you upload a movie file using TinyFTP the movie plays, but gridlines show on top of the movie image? The grid lines do not show when you upload the same movie using a different FTP server.

I have no idea why this would happen. TinyFTP transfers a file as binary data. The file should be transferred without any modifications to the data or corruptions to the file format. I would also expect the other FTP server to transfer the file in binary mode without any changes to the file data.

I do not know what would cause gridlines to display on a movie image unless it was related to the app in some way. How are you playing the movie? Is it via a B4A app or some third party android app?

If you compare the two files, the one uploaded via TinyFTP vs the one uploaded using the other FTP, they should be identical. I am not aware of any file comparison utilities for android, although I am sure there must be some available on Google Play.

I can't imagine what would cause a movie file to display with with gridlines. If the file transferred incorrectly I would expect the movie not to play at all. I wonder where the gridlines are coming from.

Does this help at all?
Barry.
 

RaymondHung

Member
Licensed User
Hello,
Sorry I did not reply sooner. I will have to mark this thread as "watched" so I am alerted if there are any posts.

If I understand the question correctly…

When you upload a movie file using TinyFTP the movie plays, but gridlines show on top of the movie image? The grid lines do not show when you upload the same movie using a different FTP server.

I have no idea why this would happen. TinyFTP transfers a file as binary data. The file should be transferred without any modifications to the data or corruptions to the file format. I would also expect the other FTP server to transfer the file in binary mode without any changes to the file data.

I do not know what would cause gridlines to display on a movie image unless it was related to the app in some way. How are you playing the movie? Is it via a B4A app or some third party android app?

If you compare the two files, the one uploaded via TinyFTP vs the one uploaded using the other FTP, they should be identical. I am not aware of any file comparison utilities for android, although I am sure there must be some available on Google Play.

I can't imagine what would cause a movie file to display with with gridlines. If the file transferred incorrectly I would expect the movie not to play at all. I wonder where the gridlines are coming from.

Does this help at all?
Barry.


Thank you for your answer. The problem may be uploaded file names with spaces, after the completion of the upload file name is incomplete. (For example: "test video 123.mpg" ---> "test").
 

RaymondHung

Member
Licensed User
Hello,
Sorry I did not reply sooner. I will have to mark this thread as "watched" so I am alerted if there are any posts.

If I understand the question correctly…

When you upload a movie file using TinyFTP the movie plays, but gridlines show on top of the movie image? The grid lines do not show when you upload the same movie using a different FTP server.

I have no idea why this would happen. TinyFTP transfers a file as binary data. The file should be transferred without any modifications to the data or corruptions to the file format. I would also expect the other FTP server to transfer the file in binary mode without any changes to the file data.

I do not know what would cause gridlines to display on a movie image unless it was related to the app in some way. How are you playing the movie? Is it via a B4A app or some third party android app?

If you compare the two files, the one uploaded via TinyFTP vs the one uploaded using the other FTP, they should be identical. I am not aware of any file comparison utilities for android, although I am sure there must be some available on Google Play.

I can't imagine what would cause a movie file to display with with gridlines. If the file transferred incorrectly I would expect the movie not to play at all. I wonder where the gridlines are coming from.

Does this help at all?
Barry.


Hi canalrun

My problem is still there, receive back data have lost, So movie files shows grid when playing.
What impact with have if change the value of "tmrData" Timer? There are ways to improve it?

Thank you very much
 

canalrun

Well-Known Member
Licensed User
Hi canalrun
My problem is still there, receive back data have lost, So movie files shows grid when playing.
What impact with have if change the value of "tmrData" Timer? There are ways to improve it?
Thank you very much

Hello,
I am sure there are definitely ways to improve Tiny FTP. I developed it to transfer small text files from a PC to a specific directory of an App.

tmrData is used to repeatedly check the data connection until the data transfer is complete. Changing the value will have an effect on overall latency, but I don't think it will have much of an effect on the transfer rate. I don't think it would have an effect on data loss unless I have a bug hidden in the code somewhere.

You say you see grid lines when the movie plays. To me this is confusing. If the data transfer were corrupt, I would not expect the movie to play at all, not have grid lines displayed on top of the movie image. If it is a streaming movie format file and it suddenly encountered a corrupt region of the file, I would expect the movie to become jerky or stop playing waiting for the data to become re-synchronized.

Maybe somebody else could offer some insight into what may be occurring.

Can you post a couple of screenshots showing the good versus bad movie image. It can be difficult to get screenshots. In the past I have borrowed a second phone to take pictures of the first phone displaying the error.

Barry.
 

RaymondHung

Member
Licensed User
Hello,
I am sure there are definitely ways to improve Tiny FTP. I developed it to transfer small text files from a PC to a specific directory of an App.

tmrData is used to repeatedly check the data connection until the data transfer is complete. Changing the value will have an effect on overall latency, but I don't think it will have much of an effect on the transfer rate. I don't think it would have an effect on data loss unless I have a bug hidden in the code somewhere.

You say you see grid lines when the movie plays. To me this is confusing. If the data transfer were corrupt, I would not expect the movie to play at all, not have grid lines displayed on top of the movie image. If it is a streaming movie format file and it suddenly encountered a corrupt region of the file, I would expect the movie to become jerky or stop playing waiting for the data to become re-synchronized.

Maybe somebody else could offer some insight into what may be occurring.

Can you post a couple of screenshots showing the good versus bad movie image. It can be difficult to get screenshots. In the past I have borrowed a second phone to take pictures of the first phone displaying the error.

Barry.



CAM00619s.jpg


CAM00627s.jpg


Thanks
 

GMan

Well-Known Member
Licensed User
Hoi Raymond,
no pics - broken links
 

GMan

Well-Known Member
Licensed User
LoL
I am OFF - Think this is a fake.
 
Top