Sftp file transfers

ignition79
#1

Our client is looking to record some custom data in csv files and periodically upload these to a different server on their network. We have no problem generating and saving the required csv files locally but the customers IT department insists that file transfers have to be done using sftp. There doesn’t appear to be any way to carry this out directly from within Ignition. We have looked at using the reporting module but this only allow FTP with SSL - this is not the same as sftp and is not acceptable to the customers IT department.

There are some python modules (pysftp, paramiko) that can easily handle sftp transfers but some of the required modules are C based and have no Jython equivalent. The best solution we have come up with is to store the files in a local directory on the Ignition server and set up a cron to sftp the files periodically to the remote server.

Does anyone have any alternative solutions to the problem of sending the files via sftp that could be done directly from within Ignition? We are free to install Ignition on either Windows or Linux platforms.

0 Likes

#2

On a linux server, I would launch a process to run the scp utility as needed to copy the files. For maximum convenience while maintaining security, provide the Ignition service user an SSH id and have the remote server accept that as an authorized key in the transfer account.

1 Like

#3

Thanks for responding. That is pretty much in line with our thinking. I was hoping to try and keep the functionality all within Ignition for ease of deployment but I think the script to use scp will be pretty simple so not a major problem.

Thanks again

0 Likes

#4

did you find a sftp solution that would work within ignition? I also need to do the exact same thing, but on a windows server.

0 Likes

#5

No I haven’t found anything. We are going to use a script on the Sever that will periodically poll a directory for the presence of a file, when we detect it we send it to the other server. We are trying this out at the moment using standard cpython installed on the server (not the jython Version that comes with Ignition) and a module called pysftp.

We have previously done a manual transfer from windows using scp which is installed with putty so it would shouldn’t be to difficult to use this called from the scripting language of your choice.

0 Likes

#6

Ah bummer.

I ended up going with Ignition writing the names of the files to a text file, and then run a bat file that grabs the filenames and then uploads them using WinSCP, which has some nice tools for auto generating the connection bat file.

0 Likes

#7

Can you share the sample project and code?

0 Likes

#8

Well there’s a ton of sensitive data there so I can’t publish any project files or the connection file, but like I said, winSCP will generate a connection .bat file that you can run with system.util.execute.

I have a separate file that I write the filepaths into, that the bat file then reads to get the names of the files to upload. Here’s the bit that I added to the .bat file that will read the csv_filenames.txt file and then grab the filenames.

set vidx=0
for /F “tokens=*” %%A in (C:\CSVScript\csv_filenames.txt) do (
SET /A vidx=!vidx! + 1
set var!vidx!=%%A
)
set var
SET file1="put "%var1%
SET file2="put "%var2%
… stuff from winscp for connecting…
%file1%^
%file2%^
“exit”

the csv_filenames.txt file should read like this when opened:

“filename1.csv”""
“filename2.csv”""

0 Likes