#1
|
|||
|
|||
Import pysftp module error
Hello Experts,
I have to perform two task(basically have to auto schedule both task as one) 1) Connect OSS server(remote server) through secureCRT and run some script on secureCRT window(same as OSS terminal window) 2)After completion of Script have to transfer the file from remote PC to my local computer. 1st part is working fine but when I am trying to call function to compete 2nd part(sftp transfer) it showing error. for sftp transfer I am using pysftp module which is showing error as "no module name sftp". So could you please help to get some solution. code to access SecureCRT and run the script: Code:
# $language = "python" # $interface = "1.0" # Connect to an SSH server using the SSH2 protocol. Specify the # username and password and hostname on the command line as well as # some SSH2 protocol specific options. import datetime from datetime import date, timedelta def main(): host = "x.x.x.x" user_name = "xx" password = "xx" session_name = "xx" cmd = "/SSH2 /L " + session_name + " /PASSWORD " + password + " " + host crt.Session.Connect(cmd) # crt.Screen.WaitForString("Prompt from dialog that is now in terminal window") # crt.Screen.Send("Response") if crt.Session.Connected: 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_NO\n") crt.Screen.WaitForString(prompt) logs_date = date.today() - timedelta(days=1) starttime = logs_date.strftime("%Y%m%d" + '.' + "0000") endtime = logs_date.strftime("%Y%m%d" + '.' + "2345") str = "sed '$ s/$/ -s " + starttime + " -e " + endtime + " -a/' Command_input.txt > Command_Input_Sudo.txt && mv Command_Input_Sudo.txt Command.txt" crt.Screen.Send(str + '\r') crt.Screen.WaitForString("Command.txt") crt.Screen.Send('echo "rnc" >> Command.txt' + '\r') crt.Screen.WaitForString("Command.txt") crt.Screen.Send('echo "q" >> Command.txt' + '\r') crt.Screen.WaitForString("Command.txt") crt.Screen.WaitForString(prompt) crt.Screen.Send("./em.sh\n") crt.Screen.Send("1\n") crt.Screen.WaitForString(">") main() Code:
import pysftp as sftp import os import sys def sftpfile(): with sftp.Connection(host = 'xxxx',port=xx,username='xx',password='xx') as s: s.cwd('/home/xx/xxx/final/') directory_structure = s.listdir_attr() for attr in directory_structure: name = attr.filename if name.startswith('Utrancell'): file_name = name remotepath = '/home/xx/EM_NO/final/'+ file_name localpath = "C:\\temp\\2019\\June\\Daily_Logfile\\xx\\" + file_name s.get(remotepath,localpath) sftpfile() So please suggest if any module available to support sftp file transfer after completion of 1st task. Regards Vikram +357-96346120 |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Display Modes | |
|
|