# Calc BASIC can’t append to network text file from Linux [closed]

Thanks to the discussion at http://ask.libreoffice.org/en/questio... I can now open CSV files on our Windows server as Calc documents, even from Linux. The key was using the ConvertToURL function, which changes the initial "file://" of a file path to "smb://", so that Linux knows to use Samba to access the file.

But now I’m trying to do some simple file access to just append a few lines of text to a log file on the Windows server, and I am again having problems. You can see from that other page that I gave a basic example of reading from a text file. That still seems to work fine, whether you use "file://" or "smb://" at the beginning of the path. But if I try to open the file for Output or Append, I always get an error 57 Device I/O error on the open command. But that doesn’t happen if I am writing to a local file on the computer, just over the network. And it doesn’t happen if I open the file for Input to read from a file on the server.

Just to make it clear, here’s what works:

fileURL = "smb://abc.def.org/server/Data/Finance/Reconcile.log"
Open fileURL For Input As #1
Line Input #1, sStr


This works if I put "file://" at the start as well, but I imagine smb is probably better, since it is required for the loadComponent call. This also works:

fileURL = "file:///home/user/Bureau/Reconcile.log"
Open fileURL For Append As #1
Print #1, "This is a test"


which is on the local machine, for Output or Append. But this fails with an error 57 on the Open call:

fileURL = "smb://abc.def.org/server/Data/Finance/Reconcile.log"
Open fileURL For Append As #1
Print #1, "This is a test"


So the problem is just writing to the text file on the server. But I use the storeAsURL method to save .ods files to the server from Linux quite a lot, so there isn’t a networking or permissions problem. In fact when I run that Open/Append command with a fileURL of a file that does not exist, it actually creates the file on the server before giving the error.

Any suggestions? (Linux Mint 16 French, LO Calc 4.1.2.3 French)

edit retag reopen merge delete

### Closed for the following reason the question is answered, right answer was accepted by Alex Kemp close date 2016-02-22 17:40:19.816931

I forgot to mention that all of these server accesses work fine from a Windows machine.

( 2014-04-08 12:12:22 +0200 )edit

I upgraded LO to 4.1.3.2 (latest stable for Linux Mint, I believe), and still have the problem.

( 2014-04-08 14:00:23 +0200 )edit

I also tried shifting to using the SimpleFileAccess methods:

oFileAccess = CreateUnoService("com.sun.star.ucb.SimpleFileAccess")
oOutStream = oFileAccess.openFileWrite(sUrl)


But using those methods, when I try to openFileWrite it gives me an UnsupportedDataSinkException.

( 2014-04-08 17:30:05 +0200 )edit

Sort by » oldest newest most voted

This appears to be a bug in LibreOffice which I am in the process of reporting here: https://bugs.freedesktop.org/show_bug.cgi?id=77902.

I found a work-around, but it’s pretty ugly, and probably quite dependent on the version of Linux that you are using. We use Linux Mint 16 for all of our office computers, so the key thing that I found was that when I connect to our server at "smb://abc.def.org/server", and then perform a logical network access in LibreOffice with Samba like this: "smb://abc.def.org/server/Data/Finance/Reconcile.log", that the operating system at some point converts that to a "normal" Linux file access that's not via Samba, and in the case of Linux Mint 16, that "normal" access will be through this path:

/run/user/1000/gvfs/smb-share:server=abc.def.org,share=server/Data/Finance/Reconcile.log


where 1000 happens to be my Linux user ID (which you can see with the "id" command). I found, however, that there was a convenient environment variable named XDG_RUNTIME_DIR which has the first part of this path, including the user ID. From what I’ve heard from other people, my guess would be that in Ubuntu this "normal" Linux file access would be through "~/.gvfs/...", but I don't know if the environment variable would help you in that case or not.

So for my work-around, I create a server path which is different depending on whether I am on a Windows or Linux machine (the "OS" environment variable will start with "Windows" on a Windows machine). On a Windows machine, we continue to use the logical server file access. On a Linux machine I create the ugly "normal" file path for server file access. So here's the code:

If Environ("OS") Like "Windows*" Then
sServerPath = "file://abc.def.org/server/"
Else
sServerPath = Environ("XDG_RUNTIME_DIR") & "/gvfs/smb-share:server=abc.def.org,share=server/"
End If
Open sServerPath & "Data/Finance/Reconcile.log" For Append As #1
Print #1, "Reconciling at: "; Format(Date, "d-mmm-yyyy"); " "; Time
Close #1


Yes, it's ugly, but it is the only work-around that I could find. Hopefully my bug report will inspire a fix, so we won't have to do these kinds of gymnastics in the future.

more