Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6555815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:51:58+00:00 2026-05-25T12:51:58+00:00

Below are five functions of my program to connect to an Ubuntu server using

  • 0

Below are five functions of my program to connect to an Ubuntu server using Paramiko. I wrote a command line script in Python that handles this perfectly, but I’m attempting to learn wxPython and I’m having a few challenges. The script works fine if I have it one function, but, being a newb, I’m trying to practice to write more efficient code. As the function are, I’m getting a message that “ssh is not defined …” I’ve tried passing parameters, and other combination of things … I guess I’m overlooking something. Can someone assist me with this?

def OnIP(self, event):
    panel=wx.Panel(self)
    dlg = wx.TextEntryDialog(None, "Enter the IP Address.",
    'Dispenser Connect', 'xxx.xxx.xxx.xxx')
    if dlg.ShowModal() == wx.ID_OK:
        ip_address = dlg.GetValue()
    if ip_address:    
        cmsg = wx.MessageDialog(None, 'Do you want to connect to: ' + ip_address,
                                'Connect', wx.YES_NO | wx.ICON_QUESTION)
        result = cmsg.ShowModal()

    if result == wx.ID_YES:
        self.DispConnect(ip_address)

        cmsg.Destroy()
    dlg.Destroy()

    return True


def GoodConnect(self):
    gdcnt = wx.MessageDialog(None, 'You are connected!', 'ConnectionStatus', wx.ICON_INFORMATION)
    gdcnt.ShowModal()
    if gdcnt.ShowModal() == wx.ID_OK:
        self.OnSearch()
    gdcnt.Destroy()    


def ErrMsg(self):
    ermsg = wx.MessageDialog(None, 'Invalid Entry!', 'ConnectionDialog', wx.ICON_ERROR)
    ermsg.ShowModal()
    ermsg.Destroy()



def DispConnect(self, address):
    pattern = r"\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b"
    port = 22
    user = 'root'
    password ='******'
    if re.match(pattern, address):
        ssh = paramiko.SSHClient()
        ssh.load_system_host_keys()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.connect(address,port,user,password)
        self.GoodConnect()
    else:
        self.ErrMsg()

def OnSearch(self, somevariable):  
    apath = '/'
    apattern = '"*.txt" -o -name "*.log"' 
    rawcommand = 'find {path} -name "*.txt" -o -name "*.log"' #{pattern}
    command1 = rawcommand.format(path=apath, pattern=apattern)
    stdin, stdout, stderr = ssh.exec_command(command1)
    filelist = stdout.read().splitlines()
    ftp = ssh.open_sftp()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:51:58+00:00Added an answer on May 25, 2026 at 12:51 pm

    You define ssh in DispConnect() but then use it again in OnSearch() where it hasn’t been defined. Since this is all taking place in the same class (I assume), make your last line in the if re.match... be

    self.ssh = ssh
    

    Then in OnSearch(), use self.ssh instead of ssh.

    That is, the local variables you use within methods aren’t available outside of those methods. Using self.ssh makes this a member of the class, and it can then be used anywhere within the class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a little problem. I wrote a program that extracts a set
For the example below: if a == 100: # Five lines of code elif
Below is my current char* to hex string function. I wrote it as an
Using the code sample below, how could I utilize the jquery cookie plugin so
I am trying to show five product-related thumbnails just below the product image (to
According to Five Simple Database Design Errors You Should Avoid by Anith Sen, using
General Overview: The function below spits out a random ID. I'm using this to
I want to use the below image as a five different buttons. In addition,
Is there any way to compare two functions in Haskell? My thought is that
My professor wants us to write a program without using arrays or vectors like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.