WebServer File Access

Hi all. Any ideas how I could access a text file on a web server to append lines in it? I have full access to the folder on the server and can set the permissions as required at the server. On MAC OS - Xojo. Cheers

A Xojo app running in this server?

You can FTP the file down, edit it, then FTP it back up. I do this with my Document Management System. Have you thought of putting this data into a database e.g. MySQL instead (much simpler!)?

You could use a TextOutputStream.

To edit a file on an FTP server?

If it is a Xojo Web Edition app then you open/write/close it the same way as with a desktop app, except it is looking to its server directory instead. I use this to build a PDF or an MP3 with the Web Edition on the server then download it automatically to the user when they click on a button. I haven’t used this to edit a file (since a database is safer) but the process is the same.

No, you cannot edit via TextOutputStream through FTP!

Oops. Sorry. I was thinking that a web app was running on the server.

I have a text file in the web server that is modified remotely daily with data. I use a PHP script that execute from the app and update the file content.

  Dim cadena As String = "some data"
  Dim form as New Dictionary
  Dim socket1 as New HTTPSocket
  Dim skt As Integer
  socket1.Yield = True
  form.Value("a") = cadena
  socket1.SetFormData form
  socket1.Post("http://www.yourwebdomain.com/process.php")
  skt = socket1.ErrorCode
  if skt = 0 Then
    MsgBox "The file update was successful!."
  Else
    MsgBox "Error updating file."+endOfLine+"Try again."
  End If

You must use a POST command in the PHP file to get the value of “a”.
The PHP process.php file would be some as this:

<?php $data = $_POST["a"]; $fp = fopen("yourtextfile.txt", "a"); fwrite ($fp, $data); fclose ($fp); ?>

Thanks Pablo, This was what I was looking for although my php script will want to append and I assume in your code it overwrites. Perfect though many thanks. Thanks to everyone else for contributing

The “a” parameter of the fopen command is for append data to text file (as you are seeking).
The “w” parameter overwrite the text file with the new data.

[quote=13535:@Pablo Schwindt]I have a text file in the web server that is modified remotely daily with data. I use a PHP script that execute from the app and update the file content.

  Dim cadena As String = "some data"
  Dim form as New Dictionary
  Dim socket1 as New HTTPSocket
  Dim skt As Integer
  socket1.Yield = True
  form.Value("a") = cadena
  socket1.SetFormData form
  socket1.Post("http://www.yourwebdomain.com/process.php")
  skt = socket1.ErrorCode
  if skt = 0 Then
    MsgBox "The file update was successful!."
  Else
    MsgBox "Error updating file."+endOfLine+"Try again."
  End If

You must use a POST command in the PHP file to get the value of “a”.
The PHP process.php file would be some as this:

<?php $data = $_POST["a"]; $fp = fopen("yourtextfile.txt", "a"); fwrite ($fp, $data); fclose ($fp); ?>[/quote]

Using the above code to write to a file on a website. How can I get a response back to my app from the server to say for instance it had been processed.