Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug when interacting with a (probably off-spec, but functional) FTP server #16

Closed
Joshfindit opened this issue Mar 31, 2022 · 1 comment · Fixed by #25
Closed

Bug when interacting with a (probably off-spec, but functional) FTP server #16

Joshfindit opened this issue Mar 31, 2022 · 1 comment · Fixed by #25

Comments

@Joshfindit
Copy link

The issue with example

Setup

require 'net/ftp'
require 'uri'

uri = URI.parse('ftp://USER:[email protected]:51041')
ftp = Net::FTP.new(uri.host, {:port=>uri.port, :debug_mode=>true, :passive=>true, :open_timeout=>10})

Result is as expected:

connect: 192.168.7.97, 51041
get: 220 B4X FTP Server
=>
#<Net::FTP:0x000000010eeeafe8
...

Login

ftp.login(uri.user, uri.password)

Result is again as expected:

put: USER USER
get: 331
put: PASS *****
get: 230
put: TYPE I
get: 200

Get list of files

Note: same issue with get*file()

ftp.list

This is where we fail:

put: TYPE A
get: 200
put: PASV
get: 227 192,168,7,97,199,99
put: TYPE I
get: 200
/usr/local/Cellar/ruby/3.1.1/lib/ruby/gems/3.1.0/gems/net-ftp-0.1.3/lib/net/ftp.rb:1399:in `parse227': 227 192,168,7,97,199,99 (Net::FTPProtoError)
	from /usr/local/Cellar/ruby/3.1.1/lib/ruby/gems/3.1.0/gems/net-ftp-0.1.3/lib/net/ftp.rb:545:in `makepasv'
	from /usr/local/Cellar/ruby/3.1.1/lib/ruby/gems/3.1.0/gems/net-ftp-0.1.3/lib/net/ftp.rb:557:in `transfercmd'
	from /usr/local/Cellar/ruby/3.1.1/lib/ruby/gems/3.1.0/gems/net-ftp-0.1.3/lib/net/ftp.rb:676:in `block (2 levels) in retrlines'
	from /usr/local/Cellar/ruby/3.1.1/lib/ruby/gems/3.1.0/gems/net-ftp-0.1.3/lib/net/ftp.rb:317:in `with_binary'
	from /usr/local/Cellar/ruby/3.1.1/lib/ruby/gems/3.1.0/gems/net-ftp-0.1.3/lib/net/ftp.rb:674:in `block in retrlines'
	from /usr/local/Cellar/ruby/3.1.1/lib/ruby/3.1.0/monitor.rb:202:in `synchronize'
	from /usr/local/Cellar/ruby/3.1.1/lib/ruby/3.1.0/monitor.rb:202:in `mon_synchronize'
	from /usr/local/Cellar/ruby/3.1.1/lib/ruby/gems/3.1.0/gems/net-ftp-0.1.3/lib/net/ftp.rb:673:in `retrlines'
	from /usr/local/Cellar/ruby/3.1.1/lib/ruby/gems/3.1.0/gems/net-ftp-0.1.3/lib/net/ftp.rb:931:in `list'
	from (irb):20:in `<main>'
	from /usr/local/Cellar/ruby/3.1.1/lib/ruby/gems/3.1.0/gems/irb-1.4.1/exe/irb:11:in `<top (required)>'
	from /usr/local/opt/ruby/bin/irb:25:in `load'
	from /usr/local/opt/ruby/bin/irb:25:in `<main>'

Interacting with the same server via netcat

$ nc -vv 192.168.7.97 51041
device.mydomain.com [192.168.7.97] 51041 (?) open
220 B4X FTP Server
USER quest
331
PASS drive
230
CWD Music
200
PASV
227 192,168,7,97,199,98
LIST
150
226

And on a data connection:

$ nc -vv device.mydomain.com 51042
device.mydomain.com [192.168.7.97] 51042 (?) open
drwxr-xr-x 1 owner group          3488 Mar  10 10:10 Vinyl Reality
 sent 0, rcvd 68
Joshfindit added a commit to Joshfindit/net-ftp that referenced this issue Mar 31, 2022
Fixes ruby#16 

Note: While some FTP servers add the brackets to the 227 response, RFC 959 does not specify them as part of the FTP protocol.
I believe this is a commonly-copy/pasted typo as the RFC docs are as follows:

>         226 Closing data connection.
>             Requested file action successful (for example, file
>             transfer or file abort).
>         227 Entering Passive Mode (h1,h2,h3,h4,p1,p2).
>         230 User logged in, proceed.
shugo added a commit that referenced this issue Dec 14, 2023
@shugo shugo closed this as completed in #25 Dec 14, 2023
@shugo
Copy link
Member

shugo commented Dec 14, 2023

@Joshfindit Sorry for the delay. I've fixed it in net-ftp-0.3.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants