无法通过Paramiko连接到SFTP

发布于 2025-01-26 15:03:37 字数 1415 浏览 5 评论 0原文

我正在尝试与paramiko建立与SFTP的连接。我能够通过使用

ssh my.domain.com

结果文件在已知_ host的第一行中同时使用host and is ip生成已知的_host文件,例如

my.domain.com,xx.xx.xxx.xx ...

当我尝试通过paramiko连接时,

host, port = 'my.domain.com,xx.xx.xxx.xx', 22
user, pwd = "xyz", "abc"

ssh = paramiko.SSHClient()
ssh.connect(host, port, username=user, password=pwd)

会出现错误

socket.gaierror: [Errno 11001] getaddrinfo failed

我在查找此之后 ,解决方案是不提及主机中的用户添加端口,等等,但是我仍然无法联系。我尝试从python代码和nown_host文件中删除my.domain.com

host, port = 'xx.xx.xxx.xx', 22  
user, pwd = "xyz", "abc"

ssh = paramiko.SSHClient()
ssh.connect(host, port, username=user, password=pwd)

但这无效。我尝试从python代码和已知_host文件中删除xx.xx.xxx.xx.xx

host, port = 'xx.xx.xxx.xx', 22
user, pwd = "xyz", "abc"

ssh = paramiko.SSHClient()
ssh.connect(host, port, username=user, password=pwd)

但这也不起作用。

如何连接到我的SFTP?

I am trying to establish a connection with an SFTP with paramiko. I was able to generate the known_hosts file in my local system by using

ssh my.domain.com

The resultant file has both the host and its IP in the first line of known_hosts, like

my.domain.com,xx.xx.xxx.xx ...

When I try to connect through paramiko,

host, port = 'my.domain.com,xx.xx.xxx.xx', 22
user, pwd = "xyz", "abc"

ssh = paramiko.SSHClient()
ssh.connect(host, port, username=user, password=pwd)

I get the error

socket.gaierror: [Errno 11001] getaddrinfo failed

After looking this up, the solutions were to not mention user in host or add port, etc. But I'm still not able to connect. I tried removing my.domain.com from both the Python code and known_hosts file,

host, port = 'xx.xx.xxx.xx', 22  
user, pwd = "xyz", "abc"

ssh = paramiko.SSHClient()
ssh.connect(host, port, username=user, password=pwd)

but that didn't work. I tried removing xx.xx.xxx.xx from both the Python code and known_hosts file,

host, port = 'xx.xx.xxx.xx', 22
user, pwd = "xyz", "abc"

ssh = paramiko.SSHClient()
ssh.connect(host, port, username=user, password=pwd)

but that didn't work either.

How do I connect to my SFTP?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你丑哭了我 2025-02-02 15:03:37

正如@tdalaney在评论中解决的那样。我编辑了nown_host文件仅指定域名并添加ssh.load_system_host_keys() connect> connect> connect 方法。

As resolved by @tdalaney in the comments. I edited the known_hosts file to only specify the domain name and added ssh.load_system_host_keys() before the connect method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文