Using sftp or scp from MoneyWorks to transfer files to/from a remote server

SFTP is a nice and easy protocol for secure transfer of files to/from other servers. It's much easier and more secure than FTP. However, the Curl library in MoneyWorks does not include SFTP (which requires the entire OpenSSH library).

However, OpenSSH command line tools are provided by the operating system (standard on Mac; optional install on Windows 10/11)

To use SFTP you can utilise the MoneyWorks External() function to access to the system scp or sftp client.

For security, MWScript is not allowed free access to the command line, so you must first symbolically link any tools you want to access into the MoneyWorks Externals folder.

On Mac

MacOS includes OpenSSH as standard. The scp command is at /usr/bin/scp. To create the symbolic link, in Terminal.app:

mkdir ~/Library/Application\ Support/Cognito/MoneyWorks\ Gold/Externals
ln -s /usr/bin/scp ~/Library/Application\ Support/Cognito/MoneyWorks\ Gold/Externals/

Windows 10/11

OpenSSH is available for Windows, but not installed by default. To install it, see Get started with OpenSSH for Windows. You'll only need the client.

At an Administrator command prompt:

mkdir "%HOMEDRIVE%%HOMEPATH%\AppData\Roaming\Cognito\MoneyWorks Gold\External"
mklink "%HOMEDRIVE%%HOMEPATH%\AppData\Roaming\Cognito\MoneyWorks Gold\External\scp.exe" C:\Windows\System32\OpenSSH\scp.exe

(the mklink is all one line)

Using SCP to upload/download files

You should use SSH keys installed in the user's .ssh folder. There are plenty of resources on line to guide you on setting this up if you don't know how. These examples assume you have working SSH keys set up, so no credentials parameters are required. Passing passwords to standard scp/sftp is not trivial (requires an additional tool, sshpass). If you really want to use password authenticaiton, you may find it easier to use putty sftp.

In MWScript, to upload the file at sourceFilePath:

External("scp", sourceFilePath, "example.com:~/Documents/")

(use "scp.exe") on Windows.

To download
Be sure to download to a location that you can access from MWScript (e.g. the cache folder)

External(if(Platform = "Mac", "scp" , "scp.exe"), "example.com:~/Documents/remotefile.txt", CacheFolderPath)
let fd = File_Open(CacheFolderPath + "remotefile.txt", "r")
Alert(File_read(fd))
File_Close(fd)
Posted in Uncategorized | Comments Off on Using sftp or scp from MoneyWorks to transfer files to/from a remote server