I need to do a script to look in some folders and send an email if there are files in these folders.
I've tried to do something like this but I get errors with the command variable and print of the folder.

This can be a lot simpler. I have no idea what you're tring to do with {print $folder}: the braces don't make any sense here, and if you're trying to include $folder in the string, you would just write $folder. You should not parse the output of ls, it's very rarely useful and often fails.

Note that the file name must be quoted for the remote shell. I mostly took care of this in my command above, by surrounding the file name in the remote command with single quotes, but that only works if $folder itself does not contain any single quotes. If your local shell is bash, ksh93 or zsh, use this instead, to quote any single quote:

Another approach which is usually more convenient is to mount the remote filesystem with sshfs and work on it through the normal filesystem interface. I recommend this unless you're working with a lot of remote servers at the same time.