# Newbie: how to use link\_to to create ftp url to download a file?

**URL:** <https://www.ruby-forum.com/t/newbie-how-to-use-link-to-to-create-ftp-url-to-download-a-file/143334>\
**Category:** Rails\
**Created:** [July 17, 2008, 2:34pm UTC](https://www.ruby-forum.com/t/newbie-how-to-use-link-to-to-create-ftp-url-to-download-a-file/143334 "2008-07-17T14:34:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Birgit\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c77e96/32.png) [@Birgit\_A](https://www.ruby-forum.com/u/Birgit_A)\
**Post date:** [July 17, 2008, 2:34pm UTC](https://www.ruby-forum.com/t/newbie-how-to-use-link-to-to-create-ftp-url-to-download-a-file/143334/1 "2008-07-17T14:34:22Z")

</div>

Hi everyone,

I’m struggling with link\_to.  
I’m trying to generate a link that will enable my web users to ftp a  
file.

Table ‘calls’ contains a field ‘filename’. There the requirement to  
download this file via ftp.

For example:  
calls.filename = ‘/project/tmp/file/README.txt’

should convert to  
/project/tmp/file/README.txt  
(or whatever the number of slashes is after ‘ftp:’)

Thanks, Birgit

–  
– Birgit A., removed\_email\_address@domain.invalid,  
– Westhawk Ltd, Albion Wharf, 19 Albion Street, Manchester M1 5LN, UK  
– Company no: 1769350  
– Registered Office:  
– 15 London Road, Stockton Heath, Warrington WA4 6SJ. UK.  
– tel.: +44 (0)161 237 0660  
– \<URL: [http://www.westhawk.co.uk](http://www.westhawk.co.uk)\>

---

<div class="post-metadata">

**Author:** ![Birgit\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c77e96/32.png) [@Birgit\_A](https://www.ruby-forum.com/u/Birgit_A)\
**Post date:** [July 17, 2008, 2:39pm UTC](https://www.ruby-forum.com/t/newbie-how-to-use-link-to-to-create-ftp-url-to-download-a-file/143334/2 "2008-07-17T14:39:39Z")

</div>

Hi,

I realise there is one more issue here.  
The ‘calls’ table also contains the ip address of the machine that hosts  
the file.

So  
calls.ip\_address = 123.456.789.123

This should find its way to the ftp url as well:  
ftp://123.456.789.123/project/tmp/file/README.txt

Thanks, Birgit

On 17/07/08 13:34, Birgit A. wrote:

> should convert to  
> /project/tmp/file/README.txt  
> (or whatever the number of slashes is after ‘ftp:’)
> 
> Thanks, Birgit

–  
– Birgit A., removed\_email\_address@domain.invalid,  
– Westhawk Ltd, Albion Wharf, 19 Albion Street, Manchester M1 5LN, UK  
– Company no: 1769350  
– Registered Office:  
– 15 London Road, Stockton Heath, Warrington WA4 6SJ. UK.  
– tel.: +44 (0)161 237 0660  
– \<URL: [http://www.westhawk.co.uk](http://www.westhawk.co.uk)\>

---

<div class="post-metadata">

**Author:** ![Birgit\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c77e96/32.png) [@Birgit\_A](https://www.ruby-forum.com/u/Birgit_A)\
**Post date:** [July 17, 2008, 2:57pm UTC](https://www.ruby-forum.com/t/newbie-how-to-use-link-to-to-create-ftp-url-to-download-a-file/143334/3 "2008-07-17T14:57:17Z")

</div>

On 17 Jul 2008, at 13:38, Birgit A. wrote:

> Hi,
> 
> I realise there is one more issue here.  
> The ‘calls’ table also contains the ip address of the machine that  
> hosts  
> the file.

Do the :protocol and :host options help you?

Fred

---

<div class="post-metadata">

**Author:** ![Birgit\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c77e96/32.png) [@Birgit\_A](https://www.ruby-forum.com/u/Birgit_A)\
**Post date:** [July 17, 2008, 3:55pm UTC](https://www.ruby-forum.com/t/newbie-how-to-use-link-to-to-create-ftp-url-to-download-a-file/143334/4 "2008-07-17T15:55:04Z")

</div>

Hi Fred,

Thanks for your help.  
I’ve seen :protocol and :host. I’m more struggling what to do with  
call.filename itself?

If “call.filename” is the value, what is the key that goes with it?  
\<%= link\_to call.filename,  
{:protocol =\> ‘ftp’, :host =\> call.ip\_address} %\>

Thanks, Birgit

On 17/07/08 13:56, Frederick C. wrote:

> Do the :protocol and :host options help you?
> 
> > > For example:  
> > > –

–  
– Birgit A., removed\_email\_address@domain.invalid,  
– Westhawk Ltd, Albion Wharf, 19 Albion Street, Manchester M1 5LN, UK  
– Company no: 1769350  
– Registered Office:  
– 15 London Road, Stockton Heath, Warrington WA4 6SJ. UK.  
– tel.: +44 (0)161 237 0660  
– \<URL: [http://www.westhawk.co.uk](http://www.westhawk.co.uk)\>

---

<div class="post-metadata">

**Author:** ![Birgit\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c77e96/32.png) [@Birgit\_A](https://www.ruby-forum.com/u/Birgit_A)\
**Post date:** [July 21, 2008, 1:14pm UTC](https://www.ruby-forum.com/t/newbie-how-to-use-link-to-to-create-ftp-url-to-download-a-file/143334/5 "2008-07-21T13:14:27Z")

</div>

Hi Everyone,

For those who might struggle like myself, this is how I solved my  
problem in the end.

I added a helper method to my call model, called to\_url():  
def to\_url(call)  
if (call.filename) then  
uri2 = URI::FTP.build({:host =\> call.ip\_address,  
:path =\> call.filename})  
uri2.to\_s  
else  
‘’  
end  
end

In my index view, I call:  
\<%= link\_to call.filename, to\_url(call) %\>

Cheers, Birgit

On 17/07/08 14:54, Birgit A. wrote:

> Thanks, Birgit
> 
> > > Thanks, Birgit
> > > 
> > > > For example:  
> > > > calls.filename = ‘/project/tmp/file/README.txt’
> > > > 
> > > > should convert to  
> > > > /project/tmp/file/  
> > > > README.txt  
> > > > (or whatever the number of slashes is after ‘ftp:’)
> > > > 
> > > > Thanks, Birgit

–  
– Birgit A., removed\_email\_address@domain.invalid,  
– Westhawk Ltd, Albion Wharf, 19 Albion Street, Manchester M1 5LN, UK  
– Company no: 1769350  
– Registered Office:  
– 15 London Road, Stockton Heath, Warrington WA4 6SJ. UK.  
– tel.: +44 (0)161 237 0660  
– \<URL: [http://www.westhawk.co.uk](http://www.westhawk.co.uk)\>
