# Net::FTP adding port as initialize/open parameter

**URL:** <https://www.ruby-forum.com/t/net-ftp-adding-port-as-initialize-open-parameter/149492>\
**Category:** Ruby\
**Created:** [September 25, 2008, 12:11pm UTC](https://www.ruby-forum.com/t/net-ftp-adding-port-as-initialize-open-parameter/149492 "2008-09-25T12:11:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lunatyq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ecccb3/32.png) [@lunatyq](https://www.ruby-forum.com/u/lunatyq)\
**Post date:** [September 25, 2008, 12:11pm UTC](https://www.ruby-forum.com/t/net-ftp-adding-port-as-initialize-open-parameter/149492/1 "2008-09-25T12:11:31Z")

</div>

Hello,

This is probably question to Rails Core:

Why there is no option to supply port parameter to Net::FTP.new/open ?

My suggestion is to add an port parameter to new and open so code below:

Net::FTP.new(“[ftp.host.com](http://ftp.host.com)”,“user”,“pass”, nil, ftp\_port)  
Net::FTP.open(“[ftp.host.com](http://ftp.host.com)”,“user”,“pass”, nil, ftp\_port)

became valid.

Code required to do this:

require ‘net/ftp’  
class Net::FTP  
def initialize(host = nil, user = nil, passwd = nil, acct = nil, port  
= FTP\_PORT)  
super()  
@binary = true  
@passive = false  
@debug\_mode = false  
@resume = false  
if host  
connect(host,port)  
if user  
login(user, passwd, acct)  
end  
end  
end

def self.open(\*args)  
if block\_given?  
ftp = new(\*args)  
begin  
yield ftp  
ensure  
ftp.close  
end  
else  
new(\*args)  
end  
end

end

Also open would be written as here, so it accepts the same parameters as  
new.

Best Regards.

Maciej

---

<div class="post-metadata">

**Author:** ![lunatyq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ecccb3/32.png) [@lunatyq](https://www.ruby-forum.com/u/lunatyq)\
**Post date:** [September 25, 2008, 1:06pm UTC](https://www.ruby-forum.com/t/net-ftp-adding-port-as-initialize-open-parameter/149492/2 "2008-09-25T13:06:38Z")

</div>

I mean Ruby Core 🙂

Regards:)

---

<div class="post-metadata">

**Author:** ![lunatyq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ecccb3/32.png) [@lunatyq](https://www.ruby-forum.com/u/lunatyq)\
**Post date:** [September 25, 2008, 1:53pm UTC](https://www.ruby-forum.com/t/net-ftp-adding-port-as-initialize-open-parameter/149492/3 "2008-09-25T13:53:13Z")

</div>

Maciej Tomaka wrote:

> I mean Ruby Core 🙂
> 
> Regards:)

You could take advantage of ruby’s open classes and make a “patch” for  
your use , making it what ftools is to File , or something like that 🙂
