views:

98

answers:

1

I'm trying to use paramiko to get a file via SFTP. It connects, I can list directories and it even downloads the first megabyte or so of the file but then it just hangs. No exception, no error, nothing. It just hangs there indefinitely.

Here's the code I'm working with:

import paramiko
t = paramiko.Transport( host )
t.connect( username=uname, password=passwd )
f = paramiko.SFTPClient.from_transport( t )
print f.listdir()
f.get( fname, fname ) #it hangs on this line :\

I have sftp access to the host in question but no shell access. The host contains a single file that I need to fetch regularly and process in a python script.

Any help with this problem or alternate solutions to doing SFTP in Python are greatly appreciated :)

A: 

I suggest you fire up Wireshark on the client and see what's happening at the protocol level. You won't be able to read the data in the packets as it will be encrypted, but you will see what's going on at the TCP/IP level and that might provide a clue.

Jim Garrison
Thanks for the advice. I set up Wireshark (didn't know ethereal had been force to change names) and ran a capture for the duration which my program was actually downloading stuff. However, I'm afraid I'm not well versed enough in low level ssh and tcp to be able make much sense of it. There don't really seem to be any errors though, it just seems to just stop!
Ulfur
Can you upload the capture file to a server where we can download it for examination?
Jim Garrison
Here you go: http://drop.io/ulfur_dumpHope it helps, I'm totally stumped by this problem :\
Ulfur
Well, your side seems to receive and acknowledge data packets normally. Then, at packet 1631 it sends a request packet and gets no response from the server. It waits 16 seconds and then closes the connection. Can you look at the server logs to see if anything's amiss there?
Jim Garrison
Exactly, that wait at packet 1631 is the "hang" I talked about.The connection closing was me killing the process because it would have waited indefinitely if I hadn't. Unfortunately I don't have access to the logs on the server in question so I can't check them. All I have is SFTP access to a single directory.I guess I'll have to contact support on the server side and see if they can figure it out. I'll post here if anything comes out of it.
Ulfur
Well, I didn't contact support so the original issue is still not resolved.However, I kept at the code and decided to try a different approach.The code is now:import paramikot = paramiko.Transport( host )t.connect( username=uname, password=passwd )f = paramiko.SFTPClient.from_transport( t )#f.get( fname, fname ) #it hangs on this line :\local = open( fname, 'w' )remote = f.open( fname, 'r' )for line in remote.xreadlines(): local.write( line )local.close()remote.close()f.close()t.close()And this works so this is what I'll use for now.Thanks for your help though Jim :)
Ulfur