- martin
winscp.StandardInput.WriteLine("call ./example.sh")
but only completes around 80% of the .sh, you can see what it does at the top of the code. It is zipping a number of files which takes around 25-30 seconds. Before posting, please read how to report bug or request support effectively.
Bug reports without an attached log file are usually useless.
It startswinscp.StandardInput.WriteLine("call ./example.sh")
but only completes around 80% of the .sh, you can see what it does at the top of the code. It is zipping a number of files which takes around 25-30 seconds.
example.sh
on the remote side or that it indeed stopped on that line of the VB.NET code? That's huge difference. If the first, what VB.NET code was running when the error occurs?
Sleep
commands. It may help. They are useless anyway.
winscp.StandardInput.WriteLine("call ./example.sh")
but only completes around 80% of the .sh, you can see what it does at the top of the code. It is zipping a number of files which takes around 25-30 seconds.
' create .sh file
Dim TextFile As New StreamWriter("c:\directory\example.sh")
TextFile.WriteLine("ddir=" & Chr(&H22) & "/tmp" & Chr(&H22))
TextFile.WriteLine("host_str=" & "'" & "hostname" & "'")
TextFile.WriteLine("tarfile=" & Chr(&H22) & "ServerLogs.tar.gz" & Chr(&H22))
TextFile.WriteLine("c_flag=0")
TextFile.WriteLine("tar 2>/dev/null --ignore-failed-read -czvf $ddir/$tarfile \")
TextFile.WriteLine("/var/log/messages \")
TextFile.WriteLine("/opt/intertel/log/* \")
TextFile.WriteLine("exit 0")
TextFile.Close()
Const logname As String = "log.xml"
' Run hidden WinSCP process
Dim winscp As Process = New Process()
winscp.StartInfo.FileName = "C:\Program Files (x86)\WinSCP\winscp.com"
winscp.StartInfo.Arguments = "/log=" + logname
winscp.StartInfo.UseShellExecute = False
winscp.StartInfo.RedirectStandardInput = True
winscp.StartInfo.RedirectStandardOutput = True
winscp.StartInfo.CreateNoWindow = True
winscp.Start()
' Feed in the scripting commands
winscp.StandardInput.WriteLine("option batch abort")
winscp.StandardInput.WriteLine("option confirm off")
winscp.StandardInput.WriteLine("open scp://10.129.8.126:22")
winscp.StandardInput.WriteLine("user")
winscp.StandardInput.WriteLine("pass")
winscp.StandardInput.WriteLine("ls")
winscp.StandardInput.WriteLine("cd /")
winscp.StandardInput.WriteLine("put c:\directory\example.sh")
System.Threading.Thread.Sleep(5000)
winscp.StandardInput.WriteLine("chmod 777 example.sh")
winscp.StandardInput.WriteLine("call ./example.sh")
System.Threading.Thread.Sleep(60000)
winscp.StandardInput.WriteLine("get /tmp/ServerLogs.tar.gz c:\directory\")
System.Threading.Thread.Sleep(60000)
winscp.StandardInput.Close()
' Collect all output (not used in this example)
Dim output As String = winscp.StandardOutput.ReadToEnd()
' Wait until WinSCP finishes
winscp.WaitForExit()
' Parse and interpret the XML log
' (Note that in case of fatal failure the log file may not exist at all)
Dim log As XPathDocument = New XPathDocument(logname)
Dim ns As XmlNamespaceManager = New XmlNamespaceManager(New NameTable())
ns.AddNamespace("w", "http://winscp.net/schema/session/1.0")
Dim nav As XPathNavigator = log.CreateNavigator()
' Success (0) or error?
If winscp.ExitCode <> 0 Then
Console.WriteLine("Error occured")
' See if there are any messages associated with the error
For Each message As XPathNavigator In nav.Select("//w:message", ns)
Console.WriteLine(message.Value)
Next
Else
' It can be worth looking for directory listing even in case of
' error as possibly only upload may fail
Dim files As XPathNodeIterator = nav.Select("//w:file", ns)
Console.WriteLine(String.Format("There are {0} files and subdirectories:", files.Count))
For Each file As XPathNavigator In files
Console.WriteLine(file.SelectSingleNode("w:filename/@value", ns).Value)
Next
End If
call ./example.sh
so thanks for that :)
call ./example.sh
but it didn't work.
call ./example.sh
instead of /console ...
.
xxxx.sh
file in the root of the server but I am unable to run it, here is the code...
winscp.StandardInput.WriteLine("option batch abort")
winscp.StandardInput.WriteLine("option confirm off")
winscp.StandardInput.WriteLine("open sftp://10.129.8.126:22")
winscp.StandardInput.WriteLine("user")
winscp.StandardInput.WriteLine("password")
winscp.StandardInput.WriteLine("ls")
winscp.StandardInput.WriteLine("cd /")
winscp.StandardInput.WriteLine("put c:\directory\example.sh")
System.Threading.Thread.Sleep(10000)
winscp.StandardInput.WriteLine("chmod 777 uc3_log.sh")
winscp.StandardInput.WriteLine("/console ./example.sh")
./example.sh
from the console within WinSCP it works fine.