net-ssh / net-sftp

Pure Ruby implementation of an SFTP (protocols 1-6) client.
http://net-ssh.github.io/
MIT License
286 stars 130 forks source link

Lockup on fetching a directory with special UTF8 characters #22

Open unregistered opened 11 years ago

unregistered commented 11 years ago

Using version 2.0.5 with net-ssh 2.6.3. OpenSSH_5.9p1, OpenSSL 0.9.8r 8 Feb 2011 (rMBP, ML).

I'm trying to list a directory with a funny UTF8 character such as 牌九 or Frosty ☃.

I connect:

@path = "/Users/me/牌九"
@handle = Net::SFTP.start(@server.host, @server.username, opts)
@entries = @handle.dir.entries(@path)

But the code never makes it past @handle.dir.entries. When I turn on :verbose => :debug for my Net::SFTP::start options, I see the following:

...
negotiating sftp protocol version, mine is 6
server reports sftp version 3
negotiated version is 3
sending opendir packet (0)
queueing packet nr 11 type 94 len 60
sent 84 bytes
read 140 bytes
received packet nr 12 type 96 len 12
channel_eof: 0
received packet nr 13 type 98 len 44
channel_request: 0 exit-status false
received packet nr 14 type 97 len 12
channel_close: 0
queueing packet nr 12 type 97 len 28
sftp channel closed
sent 52 bytes

And it stops here and stays here forever.

delano commented 11 years ago

Thanks for the report. Net-SFTP is in maintenance mode but I'm happy to pull in a fix.

elyngved commented 11 years ago

Hey @unregistered I am seeing a similar error. When the remote directory has too many files on it, trying to access the entries locks up the thread. When are are only a few files, I can retrieve them, but calling entries.each (or sftp.entries.foreach) but it does not properly parse the files, rather in my case all the file names sit among other random characters in a long string. Have you found a solution to your problem?

unregistered commented 11 years ago

Hmm I don't think I've seen the issue with large directories before. How many entries are we talking?

I haven't found time to look into this issue, but I'll post any updates here.

On Apr 1, 2013, at 3:58 PM, elyngved <notifications@github.com (mailto:notifications@github.com)> wrote:

Hey @unregistered (https://github.com/unregistered) I am seeing a similar error. When the remote directory has too many files on it, trying to access the entries locks up the thread. When are are only a few files, I can retrieve them, but calling entries.each (or sftp.entries.foreach) but it does not properly parse the files, rather in my case all the file names sit among other random characters in a long string. Have you found a solution to your problem?

— Reply to this email directly or view it on GitHub (https://github.com/net-ssh/net-sftp/issues/22#issuecomment-15742520).

unregistered commented 10 years ago

Hey, it's been awhile but I found a solution that I wanted to share.

handle.dir.entries(path) # hangs forever
handle.dir.entries(path.force_encoding(Encoding::ASCII_8BIT)) # works

I tried this on ruby-2.0.0.

elyngved commented 10 years ago

@unregistered thanks for following up. Does that just force encoding on the path string passed to the entries method? That doesn't seem to have an effect for me. In my app my path is simply the root path of '/'

unregistered commented 10 years ago

I think it may be a different issue then. My issue comes from listing a path containing UTF8 characters.