I'm writing a quick application to run off of the putty app psftp. Rather than write my own ssh application I find that running a command line will get me to where I want to be but I'm running into a situation that I need some ideas on.
I'm opening a CMD using system.diagnostics and then I throw lines at the prompt using a system.io.streamwriter writeline setup, its really basic and it works.
The problem is this, I write my lines to psftp and some require a certain amount of time to run before I can throw the next line at it. For example, when I login it takes about 500 milliseconds to process the secure login and be ready for the next command. This is a pause I know has a max of 500 milliseconds so I put a Thread.Sleep(500); right after, then it writes the next step.
The step that is tough is the one that I use to move all the files in a directory on the client machine to the remote server. in psftp terms, i'm just changing the local dir "lcd C:\\temp\\" and then move all the files "mput *.*". What I would like is to create some sort of while command that will return false when the upload completes.
My first thought is to have some sort of process record the size of the current output reader (called sOut) before the upload. Then I could write my upload command and do something like
while(currentOutputSize == sOut.ReadToEnd().length)
{
//just wait till it's done...
}
But this seems more like a work around rather than good coding.
I am new to C# which is mostly why I did not want to write my own ssh ftp client, but the other side is that this program has to serve such a basic function to upload all the files in a single directory that I did not see a reason to dedicate too much time. I could also use the same thread.sleep() function here and just set it to like 30 seconds which would probably cover it every time, but then there will be the exception that requires another 5 seconds and what happens is that my app just sits hanging.
I'd appreciate any ideas or if what I was thinking is good enough then I'll stick to that route.