Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > File Transfer

Reply
 
Thread Tools Display Modes
  #1  
Old 06-10-2019, 09:10 AM
vikram1840 vikram1840 is offline
Registered User
 
Join Date: May 2019
Posts: 13
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()
now for 2nd part:
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()
if I try to call function sftpfile() from main then showing error.

So please suggest if any module available to support sftp file transfer after completion of 1st task.

Regards
Vikram
+357-96346120
Reply With Quote
  #2  
Old 06-10-2019, 10:30 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,046
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
Reply With Quote
  #3  
Old 06-10-2019, 11:10 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,046
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
Reply With Quote
  #4  
Old 06-10-2019, 11:31 AM
vikram1840 vikram1840 is offline
Registered User
 
Join Date: May 2019
Posts: 13
Quote:
Originally Posted by bgagnon View Post
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.)
I am using SecureCRT8.5 and running on windows OS.
Basically i am running my code in SecureCRT and from there I want to perfrom sftp file transfer
Reply With Quote
  #5  
Old 06-10-2019, 11:41 AM
vikram1840 vikram1840 is offline
Registered User
 
Join Date: May 2019
Posts: 13
Quote:
Originally Posted by bgagnon View Post
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.
if possible could you please explain how you have accessed pysftp with secureCRT.It would be quite helpful for me.

Regards
Vikram
Reply With Quote
  #6  
Old 06-10-2019, 11:59 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,046
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
Reply With Quote
  #7  
Old 06-11-2019, 03:30 AM
vikram1840 vikram1840 is offline
Registered User
 
Join Date: May 2019
Posts: 13
Quote:
Originally Posted by bgagnon View Post
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.
I am trying to use this script with already connected SSH2 tab but unable to get stfp key on screen.
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
Reply With Quote
  #8  
Old 06-11-2019, 08:36 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,046
Hello Vikram,
Quote:
I am trying to use this script with already connected SSH2 tab but unable to get stfp key on screen.
What is this script?

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
Reply With Quote
  #9  
Old 06-11-2019, 08:54 AM
vikram1840 vikram1840 is offline
Registered User
 
Join Date: May 2019
Posts: 13
Quote:
Originally Posted by bgagnon View Post
Hello Vikram,

What is this script?

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.
I am using the same script without any alteration.Just updated remote and local path.
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
Reply With Quote
  #10  
Old 06-11-2019, 10:10 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,046
Hi Vikram,

Please list the explicit steps you take for your manual (without script) results.
  • Are you connected with SSH protocol to a server that supports the SFTP subsystem?

  • Does this issue occur with all your sessions?

  • Or just some sessions?
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #11  
Old 06-11-2019, 10:28 AM
vikram1840 vikram1840 is offline
Registered User
 
Join Date: May 2019
Posts: 13
Quote:
Originally Posted by bgagnon View Post
Hi Vikram,

Please list the explicit steps you take for your manual (without script) results.
  • Are you connected with SSH protocol to a server that supports the SFTP subsystem?

  • Does this issue occur with all your sessions?

  • Or just some sessions?
Hi One thing I have noticed is that port no. for SSH connection and SFTP connection are different.
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?
Reply With Quote
  #12  
Old 06-11-2019, 10:39 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,046
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
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 08:36 AM.