hi all,

can anyone tell me how to open a folder on a remote machine connected on same LAN.

I need to open a folder in the form "\\remote_machine\folder1\folder2\folder3"

Recommended Answers

All 15 Replies

Install a ssh server on the remote machine (eg copssh for windows) and use the module paramiko.

Novice20 just doesnt want to do or take advice. ;)

@richieking:

Why do u say so??? I have been following the advices and found some of them useful...Well, in the previous thread, I had replied to your post with my problem and you didn't bother to reply...well thanx for the advices

@grib:

I want to do it from inside a script, neither urllib.urlopen nor the built in open helped me

thanks for your reply too...

I'll try the paramiko module

well goodluck ;)

I'll try the paramiko module

Here is the code I use with the paramiko module

import paramiko

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("computer_name",
                username="username", password="password", allow_agent = False)

def home_dir(user):
    return "/cygdrive/c/Documents*Settings/" + user

# get the content of a user's home dir on the remote machine
i, o, e = ssh.exec_command("ls " + home_dir("username"))

# download a remote file
ftp = ssh.open_sftp()
ftp.get("remote_path/filename" , "local_path/filename")
ftp.close()

thanks a lot grib....

my guide suggested me to prefer telnet over ssh, as it is widely used. so I am thinking of using the module 'telnetlib'.

I am doing the following:

import telnetlib
...........
........
..........


user=User
password=pass

telnet=telnetlib.Telnet(host)
telnet.write(user+'\r\n')
telnet.write(password+'\r\n')after this, i need to check whether a folder exists on that host and if present, do an FTP upload.. how do I proceed?

thanks a lot grib....

my guide suggested me to prefer telnet over ssh, as it is widely used. so I am thinking of using the module 'telnetlib'.

I am doing the following:

import telnetlib
...........
........
..........


user=User
password=pass

telnet=telnetlib.Telnet(host)
telnet.write(user+'\r\n')
telnet.write(password+'\r\n')after this, i need to check whether a folder exists on that host and if present, do an FTP upload.. how do I proceed?

Apparently, you must write a command and then read until the prompt is sent, something
like

telnet.write("cd path/to/your/folder\n")
data = telnet.read_until("$ ")

But I think you should have read also with your 2 first writes for the user and the password. You should start by testing this activestate recipe http://code.activestate.com/recipes/52228/
To download a file, try telnet.write("get filename\n"). You should also obtain a list of available commands with telnet.write("help\n") etc. If you never ran telnet by hand in a terminal, it would be a good idea to do it.

thanks a lot grib :)

I am able to connect to remote host and change directory. I need to capture the return value of Telnet.write(). What is it's type and value?

I mean to say, what does it return when a path specified with cd is present and when it is not present?

thanks a lot grib :)

I am able to connect to remote host and change directory. I need to capture the return value of Telnet.write(). What is it's type and value?

I mean to say, what does it return when a path specified with cd is present and when it is not present?

if it works like in a terminal, the answer should be in the string returned by read_until("$ ")

Thanx Grib.........

I tried it, bu it gives "none" no matter the file is present or not.
Learnt that linux stores the return value of recently executed command in the variable $?. Is there any way of copying the value of $?of remote host onto a variable in the host where i run the script?

Thanx Grib.........

I tried it, bu it gives "none" no matter the file is present or not.
Learnt that linux stores the return value of recently executed command in the variable $?. Is there any way of copying the value of $?of remote host onto a variable in the host where i run the script?

I don't think you can get $*. I can't help you because I don't have a telnet server to connect to ...

k...Grib..thanx for ur effort in helping me...

is there any way to save output of individual commands over telnet session onto seperate variables instead of using Telnet.read_all() at the end? or
is there any way to save the output of Telnet.read_all() to a file , so that the output can be parsed?

k...Grib..thanx for ur effort in helping me...

is there any way to save output of individual commands over telnet session onto seperate variables instead of using Telnet.read_all() at the end? or
is there any way to save the output of Telnet.read_all() to a file , so that the output can be parsed?

Look more carefully in the activestate recipe. At line 46, there is a 'print response' statement. It means that the code displays the result of the commands. You should be able to do the same in your code. Use read_until() instead of read_all().

thanks grib for ur help :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.