CopyFileto on Xojo cloud

Hello,
I’m trying to back up some files on my Xojo Cloud server. I’m using CopyFileTo to duplicate existing files to a folder. Testing on my Mac works fine but on the cloud it won’t work.

I’m playing around with this as per the language Reference

#If TargetXojoCloud Then
  Dim sh As New Shell
  sh.Execute("chmod 666 " + F.ShellPath)
#EndIf

but I’m not really sure where to put it in the code and it’s not making any difference.

Here’s what I’m doing

F = SpecialFolder.SharedDocuments
F = F.Child("myfile.txt")

If F <> Nil and F.Exists then
  #If TargetXojoCloud Then
    Dim sh As New Shell
    sh.Execute("chmod 666 " + F.ShellPath)
  #EndIf
  F.CopyFileTo(Dest)
  i = F.LastErrorCode
  If I <> 0 then
    Log = Log + "myfile error: " + str(i) + chr(13)
  Else
    Log = Log + "myfile.txt copied successfully " + chr(13)
  End if
End if

I’m getting an error 2 in my log, I’ve done some Googling but not really found the answer.
Any help would be great thanks.
Barney

What is Dest set to?

Hi Greg,
Here’s the destination folder item, it’s just a folder created
on the server. This part of the code is working fine, the folder is being created.
Thanks.

Dest = SpecialFolder.SharedDocuments
Dest = Dest.Child("myfolderone")
Dest = Dest.Child("BackupFolder")
If Dest <> Nil and Dest.Exists then
  
  Dest = Dest.Child("TodaysBackupFolder)
  If Dest.Exists and Dest <> Nil then
    Log = "Backup folder for today already exists" + chr(13)
  Else
    try
      Dest.CreateAsFolder
    Catch
      i = F.LastErrorCode
      Log = Log + "Couldn't create todays folder error code: " + str(i) + chr(13)
    End try
  End if
Else
  Log = "Backup folder doesn't exist" + chr(13)
End if

Make sure the permissions on each of those directories is set to 777. Your app needs execute permission to write into the folders.

Thanks Greg,
I’m trying to set the permissions of the folder I’m creating to 777. I’m logging the sh.result
and it’s telling me ‘Operation not permitted’

So in the code above it’s the ‘TodaysBackupFolder’ that I create, then attempt to change permissions but with no luck. If I create this folder manually and change the permissions manually to 777 using my ftp client, my code completes successfully copying all the various files over it.

So I’m stuck on changing the permissions of the folder using the Shell command. If I have a look at the permissions of my new folder set after my code runs using my ftp client they’ve been set to 755?

Owner 1001 Read=true,Write=true,Execute=true
Group 1001 Read=true,Write=false,Execute=true
Others Read=true,Write=false,Execute=true

Here’s my code:

Dest = SpecialFolder.SharedDocuments
Dest = Dest.Child("Backup")


If Dest <> Nil and Dest.Exists then
  Dest = Dest.Child("todaysBackUp")
   
 try
      Log = Log + "About to create new folder for today: " + S + chr(13)
      Dest.CreateAsFolder
      #If TargetXojoCloud Then
        sh = New Shell
        sh.Execute("chmod 777 " + Dest.ShellPath)
        Log = Log + "Outcome of Shell Execute" + sh.Result + chr(13)
      #EndIf
    Catch
      i = F.LastErrorCode
      Log = Log + "Couldn't create todays folder error code: " + str(i) + chr(13)
   End try
 
Else
  Log = "Backup folder doesn't exist" + chr(13)
End if

Thanks.
Barney

Add SFTP to your account connect with a client and set them that way.

The issue you’re running into has to do with the fact that the user that’s running your app (Apache) is different from the user that owns the app. Apache is allowed to run the app but unless you set the permissions at the same time as creating them, you get into this situation where you can’t modify them later. The easiest way to remedy it now is to use an SFTP client, but in the future, you can avoid this by setting the permissions using Xojo:

dim f as FolderItem = SpecialFolder.SharedDocuments.Child("my folder")
If not f.exists then
    F.createFolder 
    F.permissions = &o777
End if
1 Like

Thanks Greg, This is now working for me.
Thanks for all your help.

try
  Log = Log + "About to create new folder for today: " + S + chr(13)
  #If TargetXojoCloud Then
    Dest.CreateAsFolder
    Dest.Permissions = &o777
    Log = Log + "New folder created - " + S + chr(13)
  #EndIf
Catch
  i = F.LastErrorCode
  Log = Log + "Couldn't create todays folder error code: " + str(i) + chr(13)
End try
1 Like