login about faq

I am working on a project to wrap SFTP applications into utility libraries for use in internal company projects. Our company uses Tectia but we're also looking into other libraries like WinSCP. I know that Tectia supports batch files, but we want the consumers of the library to be able to use the SFTP without needing to learn the syntax and just using .NET methods, so I decided on the path to wrap an interactive console running sftpg3. I am able to start the process, even log in successfully if I include the credentials as command-line parameters. The problem is that I am not able to interact with the process using the redirected StandardInput or get any messages using the StandardOutput(outside of the initial messages from running the process). Code below:

        Process sftpproc = new Process();
        sftpproc.StartInfo.FileName = @"sftpg3";
        sftpproc.StartInfo.UseShellExecute = false;
        sftpproc.StartInfo.RedirectStandardInput = true;
        sftpproc.StartInfo.RedirectStandardOutput = true;
        sftpproc.StartInfo.RedirectStandardError = true;
        sftpproc.StartInfo.CreateNoWindow = true;

        StringBuilder sb = new StringBuilder();

        sftpproc.OutputDataReceived += 
            (sender, args) => { sb.AppendFormat("INFO:{0}\n", args.Data); };
        sftpproc.ErrorDataReceived += 
            (sender, args) => { sb.AppendFormat("ERROR:{0}\n", args.Data); };
        sftpproc.Start();
        sftpproc.BeginOutputReadLine();
        sftpproc.BeginErrorReadLine();

        StreamWriter input = sftpproc.StandardInput;

        input.WriteLine(@"open USER@SERVER");
        input.WriteLine(@"lcd D:\");
        input.WriteLine(@"get file.txt");

        string messages = sb.ToString();

The code above works perfectly with WinSCP command-line, or when I use the console commands directly in the console. I tried redirecting the output of sftpg3 to a text file, and it is able to redirect it, and then I tried redirecting the input using '<cmd.txt' but it is unable to execute those commands (-B cmd.txt works). Is this a bug? Shouldn't console applications like sftpg3 read from standard input?

I guess another way to accomplish my requirements would be to use IKVM on the Java API but I can't find the sdk folder on the client installers from my company.

asked Oct 14 '14 at 08:57

almostchristian's gravatar image

almostchristian
6114

edited Oct 15 '14 at 07:10

I'm starting to think that sftpg3 doesn't support standard input redirection in Windows. I tried using the -B flag and it redirects the stdin to a batch file as the documentation says and the output stream was redirected in my application. Unfortunately, it doesn't fit my requirements.

(Oct 14 '14 at 10:04) almostchristian almostchristian's gravatar image

I thought that this would work. It used to work. If you want sftpg3 to read from stdin you need to specify "-" as a batch file name:

> type commands.txt | sftpg3 -B - user@server

However, it seems that this feature is broken on Windows platform and it is a known issue :( I am sorry to be a messenger of bad news.

However, if you are creating a library for your internal customers, I would recommend rather direct use of SFTP API. Tectia provides also C SFTP file transfer API (together with Java API). However, it is part of a different product: SSH Tectia ConnectSecure (that is basically client with additional features).

link

answered Oct 23 '14 at 00:11

Martin%20Dobsik's gravatar image

Martin Dobsik ♦
599126

edited Apr 19 at 21:57

Joe%20-%20Tectia%20Support's gravatar image

Joe - Tectia Support ♦♦
55215

Bad news indeed. I ended up using the Java API through IKVM.NET which works fine but doesn't allow you to set a private key for the session.

(Jan 12 '15 at 07:45) almostchristian almostchristian's gravatar image
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×55
×5
×3

Asked: Oct 14 '14 at 08:57

Seen: 3,411 times

Last updated: Apr 19 at 21:57

All user contributed content licensed under the cc-by-sa license.
Powered by OSQA.