连接到sftp服务器的python代码
我发现这段代码可以通过用户名、密码和主机连接到远程sftp服务器,但我还需要包括端口号,任何人都可以让em知道如何在这段代码和这段代码中包括端口号吗 'parmiko.util.log_to_文件(log_文件名)'log_文件名的硬代码应该是什么?? 我在unix环境中运行此代码连接到sftp服务器的python代码,python,Python,我发现这段代码可以通过用户名、密码和主机连接到远程sftp服务器,但我还需要包括端口号,任何人都可以让em知道如何在这段代码和这段代码中包括端口号吗 'parmiko.util.log_to_文件(log_文件名)'log_文件名的硬代码应该是什么?? 我在unix环境中运行此代码 import os import paramiko server, username, password = ('host', 'username', 'password') ssh = paramiko.SS
import os
import paramiko
server, username, password = ('host', 'username', 'password')
ssh = paramiko.SSHClient()
parmiko.util.log_to_file(log_filename)
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
' #In case the server's key is unknown,'
#we will be adding it automatically to the list of known hosts
ssh.load_host_keys(os.path.expanduser(os.path.join("~", ".ssh", "known_hosts")))
#Loads the user's local known host file
ssh.connect(server, username=username, password=password)
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command('ls /tmp')
print "output", ssh_stdout.read() #Reading output of the executed co'mmand
error = ssh_stderr.read()
#Reading the error stream of the executed command
print "err", error, len(error)
#Transfering files to and from the remote machine'
sftp = ssh.open_sftp()
'sftp.get(remote_path, local_path)'
sftp.put(local_path, remote_path)
sftp.close()
ssh.close()
ssh.connect()方法有一个
port=
命名参数。见
例如:
ssh.connect(server, port=portnumber, username=username, password=password)
比我早一秒到达:P+1