#1
|
|||
|
|||
Switch to sftp tab to download / upload file.
How do I switch to SFTP to get a file from a server from within my script? Manually I would goto File ~ Connect to SFTP tab, or Alt-P. In my script I would want to do this automatically and place the file in a specified folder on my client machine.
Not sure if this would be problematic, but i am not using "tab safe" scripting. all of my commands are crt.screen.xxxx instead of objTab.screen.xxx. I am over 2000 lines deep into my script so changing it would be a little problematic. =] Version 6.7.3 (build 292) |
#2
|
|||
|
|||
Hi bstedh,
It sounds like the SFTP tab will not be active when you start the script, to send commands to it will likely require use of the Tab object. Have you reviewed the SFTP Tab Automation Example?
__________________
Thanks, --Eric VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#3
|
|||
|
|||
That looks to be exactly what I was looking for. Thanks, I will give it a try.
Can the SFTP option "local directory" be changed from within the script? |
#4
|
|||
|
|||
Hi bstedh,
It can, please see the below code snippet from the example script. Code:
' Change local directory (local to the SecureCRT Windows machine) to the ' folder in which the downloaded file should be saved: objSFTPTab.Screen.Send "lcd C:\Temp" & vbcr objSFTPTab.Screen.WaitForString "sftp> "
__________________
Thanks, --Eric VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#5
|
|||
|
|||
Just saw that =]
missed it the first time i read through the script... |
#6
|
|||
|
|||
bstedh,
I know the feeling of being excited to get started ![]() I hope this helps point you in the right direction.
__________________
Thanks, --Eric VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#7
|
|||
|
|||
Ok, I wrote my function.
I still have to write the function that creates the file before I can test it. But its time to go cook dinner. "Tomorrow is another day" The only thing I really changed was to switch to waitforstring instead of get. Not sure if that will be an issue. Code:
Function BSMsftpGET(FileName,Destination) Set objSFTPTab = crt.GetScriptTab.ConnectSFTP strScreenText = _ objSFTPTab.Screen.WaitforString("sftp>",5) If strScreenText = 0 Then BSMsftpGET = "TimeOut" objSFTPTab.Close Exit Function End If objSFTPTab.Screen.Send "ls -l" & vbcr strFileListing = objSFTPTab.Screen.ReadString("sftp>") If InStr(strFileListing,FileName) Then BSMsftpGET = "NoFile" objSFTPTab.Close Exit Function End If objSFTPTab.Screen.Send "lcd " & Destination & vbcr objSFTPTab.Screen.WaitForString "sftp>" objSFTPTab.Screen.Send "get " & FileName & vbcr strResults = objSFTPTab.Screen.ReadString("sftp>") If Instr(strResults, "100%") > 0 Then BSMsftpGET = "Success" Else BSMsftpGET = "Fail" End If objSFTPTab.Close End Function |
#8
|
|||
|
|||
![]()
Ok, got the file generation portion completed and was able to test the download function. I had to make a few tweaks but it appears to be working good.
Code:
Function f9SFTP(FileName,Destination,getput) Set objSFTPTab = crt.GetScriptTab.ConnectSFTP strScreenText = objSFTPTab.Screen.WaitforString("sftp>",5) If strScreenText = 0 Then f9SFTP = "TimeOut" objSFTPTab.Close Exit Function End If If getput = "get" Then objSFTPTab.Screen.Send "ls " & FileName & vbcr strFileListing = objSFTPTab.Screen.ReadString("sftp>") If InStr(strFileListing,"cannot") Then f9SFTP = "NoFile" objSFTPTab.Close Exit Function End If End If objSFTPTab.Screen.Send "lcd " & Destination & vbcr objSFTPTab.Screen.WaitForString "sftp>" objSFTPTab.Screen.Send getput & " " & FileName & vbcr strResults = objSFTPTab.Screen.ReadString("sftp>") If Instr(strResults,"100%") > 0 Then f9SFTP = "Success" objSFTPTab.Screen.Send "rm " & FileName & vbCr objSFTPTab.Screen.WaitForString "sftp>" Else f9SFTP = "Fail" End If objSFTPTab.Close End Function
__________________
Version 6.7.3 (build 292) Last edited by bstedh; 01-07-2018 at 05:22 PM. |
#9
|
|||
|
|||
Hi bstedh,
Thanks for the update, I'm glad to hear that you were able to get the functionality you're looking for.
__________________
Thanks, --Eric VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
![]() |
Tags |
sftp |
Thread Tools | |
Display Modes | Rate This Thread |
|
|