Welcome to the VanDyke Software Forums

Join the discussion today!

Go Back   VanDyke Software Forums > Scripting

Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
Old 09-16-2019, 06:27 AM
vikram1840 vikram1840 is offline
Registered User
Join Date: May 2019
Posts: 21
Code not executed as per script

Hello Expert,

Please help to resolve issue I am facing.

My purpose
1) To autoconnect SSh2 and run some command and store the output
2) Transfer the stored output to my local PC through sftp connection.

In my cases I have written two function one is main() in which I have written code to autoconnect SSh2 and run some command at remote server and inside this main I am calling sftp_transfer function.
Means once command will finish then only call sftp_transfer function.

In my code it happens that without executing main function completely it call to transfer function.
so plz suggest.
I am doing some mistake with waitforstring I think so.

# $language = "python"
# $interface = "1.0"

def main():
    host = "x.x.x.x"
    user_name = "xxxx"
    password = "xxxx"
    cmd = "/SSH2 /L " + user_name + " /PASSWORD " + password + " " + host
    crt.Screen.Synchronous = True
    row = crt.Screen.CurrentRow
    prompt = crt.Screen.Get(row, 0, row, crt.Screen.CurrentColumn-1)
    prompt = prompt.strip()
    crt.Screen.Send("cd EM_LTE\n")

def sftp_transfer():
    objSFTPTab = crt.GetScriptTab().ConnectSftp()
    objSFTPTab.Screen.Synchronous = False
    while True:
        strScreenText = objSFTPTab.Screen.Get2(
        if "sftp> " in strScreenText:
    objSFTPTab.Screen.Synchronous = True
    objSFTPTab.Screen.Send("ls -l\r")
    strFileListing = objSFTPTab.Screen.ReadString("sftp> ")
    objSFTPTab.Screen.Send("lcd C:\Macro\ENM\r")
    objSFTPTab.Screen.WaitForString("sftp> ")
    objSFTPTab.Screen.Send("cd /home/shared/f22220/EM_LTE/Output/mobatch_RNC\r")
    objSFTPTab.Screen.WaitForString("sftp> ")
    objSFTPTab.Screen.Send("get all.txt\r")
    strResults = objSFTPTab.Screen.ReadString("sftp> ")
    if "100%" in strResults:
        vDataLines = strResults.split("\r\n")
        crt.Dialog.MessageBox("File transfer successful: \r\r" + vDataLines[-2])
        crt.Dialog.MessageBox("Failed to get file!\r\r" + strResults)

    # Close the SFTP tab once we're done

in above code without completion of autoconnect it call sftp_transfer function which is not desirable.
Reply With Quote

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
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:25 AM.