views:

123

answers:

3

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.

+1  A: 

You are mixing SSH and SFTP. SSH opens a secure connection, but SFTP is a separate protocol which is run over SSH connection and requires a separate tunnel. In OpenSSH (and it's Windows Port, copSSH) it's sftp.exe application that does SFTP.

Now about FTP vs SFTP. Please check an article that explains the difference between SFTP and FTP(S). If LabView supports FTP, this doesn't help you when you need to perform SFTP transfers.

I don't know whether you can use external ActiveX controls in LabView. If you can, you are welcome to check our SFTP ActiveX control, that will let you do the transfer. If all you can do is call external application, then you'd have to use copSSH's sftp.exe.

Eugene Mayevski 'EldoS Corp
OK, I am using the sftp.exe that comes with the copSSH package, sorry if I got confused with the terms, it's all new to me. LabVIEW only supports basic TCP/IP protocols so we can't transfer the files over a secure protocol without using some external code. I did look at the linked ActiveX control but for this application using the sftp executable from copSSH is recommended by our data centre team.
Swinders
+1  A: 

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.

nekomatic
Looks like this has given me the answer I needed. The sftp command provided with copssh also has a `-b` switch. Couldn't find any reference to this online but using the `-h` switch gave me the correct usage. Looks like sftp has the switch and script before the hostname, `sftp -b batchfile user@host`. Thanks
Swinders
A: 

I have been using WinSCP which has a command line version, winscp.com. It supports sftp and allows synchronize, keepuptodate, get, put and delete on folders and files. One word of warning, keepuptodate depends on an unbroken connection. Although WinSCP can remake a connection automatically, keepuptodate cannot. I suspect it is based on Microsoft's .NET SystemIO FileSystemWatcher. I therefore do a regular synchronize to keep a mirror of my source folder tree on the remote target.

sluice