Also for some reason it was working yesterday but it isn’t working today. I don’t think its the code but some external matter.
Anyways
Dim virtualFolder As String = "~/Scripts/"
Dim physicalFolder As String = Server.MapPath(virtualFolder)
Dim unixLogin As String = (USERNAME & "@" & COMPUTERNAME & ":" & UNIXSCRIPTNAME)
' Send file to Unix server via pscp
Dim Proc As New System.Diagnostics.Process
Proc.StartInfo = New ProcessStartInfo("C:\Windows\System32\cmd.exe")
'MsgBox("/C C:\pscp.exe -pw " & PASSWORD & " " & physicalFolder & "\" & UNIXSCRIPTNAME & " " & unixLogin)
Proc.StartInfo.Arguments = "C:\pscp.exe -pw " & PASSWORD & " " & physicalFolder & "\" & UNIXSCRIPTNAME & " " & USERNAME & "@" & COMPUTERNAME & ":" & UNIXSCRIPTNAME
Proc.StartInfo.RedirectStandardInput = True
Proc.StartInfo.RedirectStandardOutput = False
Proc.StartInfo.UseShellExecute = False
'Proc.StartInfo.CreateNoWindow = True
Proc.Start()
' Allows script to execute sequentially instead of simultaneously
Proc.WaitForExit()
' Make file executable
Proc.StartInfo = New ProcessStartInfo("C:\plink.exe")
'MsgBox("-ssh -pw " & PASSWORD & " " & USERNAME & "@" & COMPUTERNAME & " chmod u+x ./" & UNIXSCRIPTNAME)
Proc.StartInfo.Arguments = "-ssh -pw " & PASSWORD & " " & USERNAME & "@" & COMPUTERNAME & " chmod u+x ./" & UNIXSCRIPTNAME
Proc.StartInfo.RedirectStandardInput = True
Proc.StartInfo.RedirectStandardOutput = False
Proc.StartInfo.UseShellExecute = False
' Proc.StartInfo.CreateNoWindow = True
Proc.Start()
Proc.WaitForExit()
' Execute File
Proc.StartInfo = New ProcessStartInfo("C:\plink.exe")
Proc.StartInfo.Arguments = "-ssh -pw " & PASSWORD & " " & USERNAME & "@" & COMPUTERNAME & " ./" & UNIXSCRIPTNAME
Proc.StartInfo.RedirectStandardInput = True
Proc.StartInfo.RedirectStandardOutput = False
Proc.StartInfo.UseShellExecute = False
'Proc.StartInfo.CreateNoWindow = True
Proc.Start()
Proc.WaitForExit()
' Remove File
Proc.StartInfo = New ProcessStartInfo("C:\plink.exe")
Proc.StartInfo.Arguments = "-ssh -pw " & PASSWORD & " " & USERNAME & "@" & COMPUTERNAME & " rm ./" & UNIXSCRIPTNAME
Proc.StartInfo.RedirectStandardInput = True
Proc.StartInfo.RedirectStandardOutput = False
Proc.StartInfo.UseShellExecute = False
'Proc.StartInfo.CreateNoWindow = True
Proc.Start()
Proc.WaitForExit()
Can this be shortened?
I am…
1) Sending a file to a unix system
2) Making it executable
3) Running the file (its a script)
4) Deleting it after
You may want to see if this will work for you. I do not have an Unix system to check it on, but it seems to populate the process correctly. I also dummied up default values for your variables for testing purposes. This takes away a lot of the redundancy and shortens the amount of code.
End Class