Unable to write to Local SMB server With FileManager.copy()

Hey all! I recently set up an SMB server on a local computer, and have connected it to my iPad so that I can easily save screen recordings and other large files externally.

I had things working last night, but after having to re-add my permissions in scriptable after disconnected from the server, my script to copy files and paste them on my server has broken! I get an error “could not copy files to ‘SMB’” (SMB being the bookmarkedPath name), but curiously there is an empty file created on the server after running.

I have added it to my file bookmarks and I can read/write from the files app manually without issue. Running it from a ‘run script’ shortcut in the files app, with the script set to always run in app.

Here is my code:

let file = args.fileURLs[0]
let bp = FileManager.local()

let fileName = file.split('/');
fileName = fileName[fileName.length-1];

let destination = bp.bookmarkedPath('SMB') + '/' + fileName
bp.copy(file, destination)
  1. Have you tried restarting both the iPad and the server to rule out any general glitchiness?
  2. What OS and App versions are you running? Any betas in there?
  3. What happens if you retry after deleting the server file?
  4. What happens if you try a different file in the same location on the server?
  5. What happens if you try a different file in a different location on the same server?
  6. What happens if you try a different file in a different location on a different server?
1 Like
  1. I did try restarting the iPad and the samba service that I’m using to host the server, and I tried disconnecting and reconnecting to the server from the iPad, but I didn’t reboot the whole physical machine that’s running the server. I’ll give that a shot

  2. I’m on iPadOS 13.6.1, and Scriptable 1.4.14. No betas

  3. If I retry after deleting the server file, I get the same error and the same empty file

  4. Different file in the same location yields the same results, I’ve tried a couple different file types as well

  5. Same thing :frowning:

  6. I only have the one server connection so I’m not sure!

I’ve solved the issue! Admittedly it takes about as many clicks to use this shortcut as it would be to just move stuff manually so it’s kind of silly, but if anyone down the road stumbles upon this question looking for a similar answer, this may be helpful.

Instead of copying, I realized that there is also a write method of FileManager which takes a destination and data as its arguments, and a read method which you can use to read file data. I combined those and it works great to copy files to my SMB server. Here’s the code:

let file = args.fileURLs[0]
let bp = FileManager.local()

let theFile = bp.fileName(file, true)

let destination = bp.bookmarkedPath('smbserver') + '/' + theFile

bp.write(destination, bp.read(file))