Android Tutorial Android FTP tutorial

Status
Not open for further replies.

refsmmat

Member
Licensed User
Longtime User
FTP upload - append file on server

Hello Erel et al,

Many thanks for the development work on the NET library. I have found it very easy to use.

Is it possible to use it to append an existing text file on an ftp server?

Rather than upload a file, I would like to be able to just send the new data (ASCII) to add a line to the file.

I understand I have the option to download the file and append it on the Android device, but over time, as the file grows, this will introduce other complications.

Thanks for your advice.

Regards,

REFSMMAT
 

wl

Well-Known Member
Licensed User
Longtime User
The FTP protocol does not support this option.

Your only option is to write a HTTP page or webservice to which you can send the new lines. The HTTP page can then append these lines to an existing file.
 

refsmmat

Member
Licensed User
Longtime User
The FTP protocol does not support this option.

Your only option is to write a HTTP page or webservice to which you can send the new lines. The HTTP page can then append these lines to an existing file.

Hi WL, thanks for the response.

The reason I asked the question is I am currently performing this ftp file append operation using Arduino with a GPRS modem.
(AT+FTPPUTOPT=APPE). The ftp server is nothing special, but it does accept appending of files on the server.

The limitation is I am not uploading a file, but rather the bytes to append the existing file on the ftp server. This doesn't bother me as it suited my application.

I am switching this activity from Arduino to an Android device to get more capability in other areas. Losing the append function is a small price to pay.

Thanks again.
Regards,
REFSMMAT
 

refsmmat

Member
Licensed User
Longtime User
The FTP protocol does not support this option.

Your only option is to write a HTTP page or webservice to which you can send the new lines. The HTTP page can then append these lines to an existing file.
Hi WL, thanks for the response.

The reason I asked the question is I am currently performing this ftp file append operation using Arduino with a GPRS modem.
(AT+FTPPUTOPT=APPE). The ftp server is nothing special, but it does accept appending of files on the server.

The limitation is I am not uploading a file, but rather the bytes to append the existing file on the ftp server. This doesn't bother me as it suited my application.

I am switching this activity from Arduino to an Android device to get more capability in other areas. Losing the append function is a small price to pay.

Thanks again.
Regards,
REFSMMAT
 

wl

Well-Known Member
Licensed User
Longtime User
Just to be clear:

Although FTP does not standard support this, you could decide to write your own FTP server (in .NET for example there are a few good libraries for this) that would receive your files and append it.

But that would not be a standard FTP server, so I would stick to the HTTP upload as stated before.
 

rfresh

Well-Known Member
Licensed User
Longtime User
Is SFTP supported yet and if not, do you know when it might be? There are heavy mandates on eCommerce websites for PCI compliance and one of requirements is SFTP access only. I need SFTP capability in the FTP tool that I want to build using your product. Without SFTP there is no need for me to use your product. Thanks.

I was able to make this Post but now I can't post replies.

I found this free java SFTP Lib at http://www.zehon.com/index.html

Are we able to make use of this kind of lib?
 
Last edited:

AscySoft

Active Member
Licensed User
Longtime User

As far as I know, there isn't and I really don't know if/when this 'feature' will become available. I was searching too for this protocol, but I manage to do some encrypted files and then I sent them over FTP as usual. But this was in my case.
Sorry for my (Johnny) English!

see my question fist page of this thread!
 
Last edited:

refsmmat

Member
Licensed User
Longtime User

Ok - thanks.

Regards,
Stephen
 

Vinians2006

Active Member
Licensed User
Longtime User
Where should I put the Close method ? Im using a List object that hold all files that I want to download. So I have a FOR loop to handle this task. How can I know if was an error and abort the for loop ? And how about Pause and Resume in tha activity ? Please make a complete example for us.
Thanks!
 

Vinians2006

Active Member
Licensed User
Longtime User
It is better to have a list and then download the files one after another. When one file completes you should remove it from the list and start the next download.
hum.. ok I will try. Another question is that I was trying to create a "code module" especilist in donwload and upload a file easly but it seems that the FTP object only works in a Activity module ?
Thanks in advance!
 

biometrics

Active Member
Licensed User
Longtime User
Hi Erel,

I am converting our exiting application from the old FTP library to the new one. I notice the big difference being that the old one was procedural function calls vs the new one being event driven.

We have a large code module I need to convert that is procedural based and rewriting it to be purely event driven would be a massive job. I was hoping to achieve the same effect as follows:

B4X:
Sub Process_Globals
    Dim libFTP As FTP
    Dim bCommandSuccessful As Boolean
    Dim sFtpServer As String
    Dim sFtpUsername As String
    Dim sFtpPassword As String
    Dim sFtpDirectory As String
End Sub

Sub Activity_Create(FirstTime As Boolean)
    libFTP.Initialize("libFTP", sFtpServer, 21, sFtpUsername, sFtpPassword)
    FTPList
End Sub

Sub FTPList()
    bCommandCompleted = False
    libFTP.List(sFtpDirectory)
    Do Until bCommandCompleted
        DoEvents
    Loop
End Sub

Sub libFTP_ListCompleted(ServerPath As String, Success As Boolean, Folders() As FTPEntry, Files() As FTPEntry)
    bCommandCompleted = True
End Sub

But it seems the event won't fire unless I do a Return out of the FTPList Sub. Doing the Do/DoEvents/Loop stops the event from firing.

How can I do this?
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
The FTP operations must be event driven. Otherwise they will block the main thread and will crash the application.

You cannot use such a loop. DoEvents will only process UI related messages.
You should instead use a global variable to handle the state and continue the program flow when the download completes.
This is a bit more complicated but it is the only correct way to build it.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…