0

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"

3
Contributors
15
Replies
16
Views
6 Years
Discussion Span
Last Post by novice20
0

@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...

0

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()

Edited by Gribouillis: n/a

0

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?

0

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.

Edited by Gribouillis: n/a

0

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?

0

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("$ ")

0

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?

0

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 ...

0

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?

Edited by novice20: n/a

0

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().

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.