how to set a time out for SFTP server connection using paramiko?

I am struggling to set timeout option for SFTP connection using paramiko library.

if i am moving 10GB file, after a period of time the process got stopped with out any error.There is no script issues. after I found the server got disconnected so only the file upload process not completed successfully.

can any one know how to set timeout parameter using paramiko SFTP client.?

script:

s3_conn = S3Connection(profile_name=dest_profile)
bucket = s3_conn.get_bucket(tgt_bucket_nm)
proxy = paramiko.proxy.ProxyCommand('/usr/bin/nc --proxy proxy_host:8080 %s %s' % (ftp_host, ftp_port) )
transport = paramiko.Transport(proxy)
transport.connect(username=ftp_username, password=ftp_password)
ftp_conn = paramiko.SFTPClient.from_transport(transport)

Could you please let me know if any one need more clarification of my question.

Thanks in advance


you can set the timeout for the channel using below line

ftp_conn.get_channel().settimeout(1000) time is in seconds


I'm afraid you have to use socket with settimeout:

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
    sock.settimeout(3)  # see here
        sock.connect((HOST, PORT))
        with paramiko.Transport(sock) as transport:
            ...

it raise socket.timeout

链接地址: http://www.djcxy.com/p/33646.html

上一篇: 如何研究设计模式?

下一篇: 如何使用paramiko为SFTP服务器连接设置超时?