Search code examples
sftplabviewcopssh

Automate sending of files through sftp using copssh


Every month we send reports to a server using FTP. We run a query on a database to create the files then use the ftp functionality in LabVIEW to do the transfer. This runs on a Windows system.

This works fine but now we have to switch to using SFTP and the CopSSH package has been recommended. As LabVIEW has no native SFTP functionality we are looking at how we can use the sftp.exe application from CopSSH.

From the command prompt we have set up the encryption and made the initial connection using sftp username@host and entered the password. This has been confirmed by the team on the server side so connection to the server is set up. Now we just use sftp username@host and no password is required.

Where we are struggling is how to initiate the transfer from our LabVIEW code. We are able to call system commands using the System Exec VI but is there a way to pass a list of functions to the SFTP executable?

The commands used to transfer the files when we type it at the command prompt are:

sftp username@host
put c:/Data/File1.txt remoteFile1
put c:/Data/File2.txt remoteFile2
put c:/Data/File3.txt remoteFile3
quit

This works from the command prompt but I am looking to just call the sftp executable with a list of files to transfer. I don't think this would be specific to LabVIEW as you could use a batch file to run from a scheduled job.

LabVIEW can call ActiveX and .net but we really need to use this specific application.


Solution

  • If copssh's sftp.exe is a command line utility, and System Exec in your version of LabVIEW has the 'standard input' terminal (present at least since 8.5), you should be able to simply wire the commands you want sftp.exe to run into the standard input terminal.

    If that doesn't work for some reason, could you use PuTTY instead of copssh? The documentation for PuTTY's PSFTP component says that it can execute a sequence of commands in a script file using the -b command line switch, e.g.

    psftp user@hostname -b myscript.scr
    

    so you could have your LabVIEW program create the script file then run it with System Exec.