Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
270 views
in Technique[技术] by (71.8m points)

python - Connecting to SFTP server with Paramiko fails with "An integer is required (got type str)"

I'm trying to run the following code :

#!/data/go_dl/resources/miniconda3/envs/stg01.nifi_Env/bin/python
import sys
import paramiko
import socket

sftpHost = 'eng-test-host'
sftpPort = '22'
sftpUser = 'user_1'
sftpPass = '123456'
sftpPathSource = '/tmp/poc/'
localPath = '/data/poc/'
sftpIMGFiles = 'test.IMG'


transport=paramiko.Transport((sftpHost, sftpPort))
transport.connect(username=sftpUser, password=sftpPass)
sftp=paramiko.SFTPClient.from_transport(transport)

sftp.put(sftpPathSource + sftpIMGFiles +  localPath + sftpIMGFiles)
sftp.close()
transport.close()

class FastTransport(paramiko.Transport):
    def __init__(self, sock):
        super(FastTransport, self).__init__(sock)

But I'm getting this error :

Traceback (most recent call last):
  File "gettingTtsFile.py", line 18, in <module>
    transport=paramiko.Transport((sftpHost, sftpPort))
  File "/data/go_dl/resources/miniconda3/lib/python3.8/site-packages/paramiko/transport.py", line 409, in __init__
    retry_on_signal(lambda: sock.connect((hostname, port)))
  File "/data/go_dl/resources/miniconda3/lib/python3.8/site-packages/paramiko/util.py", line 283, in retry_on_signal
    return function()
  File "/data/go_dl/resources/miniconda3/lib/python3.8/site-packages/paramiko/transport.py", line 409, in <lambda>
    retry_on_signal(lambda: sock.connect((hostname, port)))
TypeError: an integer is required (got type str)

Can someone help me? The Python version that I'm trying to run is 3.8.5 and Paramiko is 2.7.2.

Thanks

question from:https://stackoverflow.com/questions/65932669/connecting-to-sftp-server-with-paramiko-fails-with-an-integer-is-required-got

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The port number arg in the paramiko.Transport needs to be an int and not str

sftpHost = 'eng-test-host'
sftpPort = 22 # Note this is int and not str

transport=paramiko.Transport((sftpHost, sftpPort))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...