Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 01-04-2018, 03:47 PM
bstedh bstedh is offline
Registered User
 
Join Date: Jan 2018
Posts: 41
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)
Reply With Quote
  #2  
Old 01-04-2018, 04:03 PM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
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
Reply With Quote
  #3  
Old 01-04-2018, 04:40 PM
bstedh bstedh is offline
Registered User
 
Join Date: Jan 2018
Posts: 41
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?
Reply With Quote
  #4  
Old 01-04-2018, 04:43 PM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
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
Reply With Quote
  #5  
Old 01-04-2018, 04:52 PM
bstedh bstedh is offline
Registered User
 
Join Date: Jan 2018
Posts: 41
Just saw that =]

missed it the first time i read through the script...
Reply With Quote
  #6  
Old 01-04-2018, 04:54 PM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
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
Reply With Quote
  #7  
Old 01-04-2018, 05:14 PM
bstedh bstedh is offline
Registered User
 
Join Date: Jan 2018
Posts: 41
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
Reply With Quote
  #8  
Old 01-07-2018, 02:38 PM
bstedh bstedh is offline
Registered User
 
Join Date: Jan 2018
Posts: 41
Thumbs up

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.
Reply With Quote
  #9  
Old 01-08-2018, 08:25 AM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
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
Reply With Quote
Reply

Tags
sftp

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 04:56 AM.