#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 |
#2
|
|||
|
|||
Hi Vikram,
What version of SecureCRT are you using? On what OS/platform? If on Windows, how did you import the custom module? (It's not one that's included.)
__________________
Thanks, --Brenda VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#3
|
|||
|
|||
Hi Vikram,
As a note, SecureCRT does have its own sftp mechanism, the Sftp tab. See example script here. But I was able to get pysftp working on SecureCRT/Linux. For Windows, that module may depend on too many other missing modules.
__________________
Thanks, --Brenda VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#4
|
|||
|
|||
Quote:
Basically i am running my code in SecureCRT and from there I want to perfrom sftp file transfer |
#5
|
|||
|
|||
Quote:
Regards Vikram |
#6
|
|||
|
|||
Hi Vikram,
To clarify, I have not been able to use pysftp in SecureCRT/Windows. On my Ubuntu Linux VM, I installed pysftp using pip and then just ran a simple script I found online, altering the print statement to a MessageBox instead: Code:
import pysftp srv = pysftp.Connection(host="my_host", username="my_username", password="my_pwd") # Get the directory and file listing data = srv.listdir() # Closes the connection srv.close() # Prints out the directories and files, line by line for i in data: crt.Dialog.MessageBox(i)
__________________
Thanks, --Brenda VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#7
|
|||
|
|||
Quote:
Even I have tried with right click and connect sftp connection and the same output. Still waiting for sftp> keyword. I am using secureCRT8.5 and I think this support SFTP connection as well. So is there anything I am missing here. Plz suggest Regards Vikram |
#8
|
|||
|
|||
Hello Vikram,
Quote:
The example sftp tab script with no alterations? Or did you incorporate that example script into your own script? If not the example script as-is, I will need to see a copy of your script. You can post it here if it does not include sensitive data. If there is sensitive data, email it to support@vandyke.com and reference Attn Brenda - Forum Thread #13585 in the subject line.
__________________
Thanks, --Brenda VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#9
|
|||
|
|||
Quote:
Apart from it even without using script while I am trying to connect"coonect SFTP connection" of running SSH2 connection it also not reflecting any sftp keyword. Regards Vikram |
#10
|
|||
|
|||
Hi Vikram,
Please list the explicit steps you take for your manual (without script) results.
__________________
Thanks, --Brenda VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#11
|
|||
|
|||
Quote:
We have port 8022 for SSH and 8024 for SFTP. So may be due to this I am unable to get SFTP through SSH connection. So is there any solution in this cases? |
#12
|
|||
|
|||
Hi Vikram,
No, not that I know of at this time. A colleague did discover the major missing dependency that would prevent pysftp working in SecureCRT/Windows is that we don't include the _socket module. I have added this thread to a feature request in our product enhancement database to add native support for _socket Python module on Windows. Should a future release of SecureCRT include this feature, notification will be posted here. If you prefer direct email notification, send an email to support@vandyke.com and include "Feature Request - Forum Thread #13585" in the subject line or use this form from the support page of our website.
__________________
Thanks, --Brenda VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#13
|
|||
|
|||
Hi all,
I wanted to let you know the __socket module should be available as of SecureCRT v9.0, currently in beta 1 release, since this support was added: Changes in SecureCRT 9.0 (Beta 1) -- September 24, 2020 ------------------------------------------------------- New Features:
Note that this is Windows only support at this time. In fact, we released beta 1 installers *only* for Windows. We hope to include all platforms in later releases.
__________________
Thanks, --Brenda VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Display Modes | |
|
|