Forum: Ruby problems ftp'ing with RUBY

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B58c6eef325656d513d26e2c3ae6bfd9?d=identicon&s=25 Peter Bailey (peterbailey)
on 2006-05-03 17:19
I need to ftp PDF files to our printer. Using the script below, I'm
trying to do that, but, it ain't working. It just sits there. I ftp
manually to the same site to see if anything's getting there, and, no,
nothing is. Can someone see what's wrong here? I've tried it with IRB,
too, but that doesn't work either.

Thanks.

require 'net/ftp'
indexfiles = Dir.glob("*.pdf")
indexfiles.each do |indexfile|
  ftp = Net::FTP.open('mpc.bna.com') do |ftp|
  ftp.login('username','password')
  ftp.chdir('/data/bnaindex')
  ftp.putbinaryfile("indexfile")
  end
end
Cb48ca5059faf7409a5ab3745a964696?d=identicon&s=25 unknown (Guest)
on 2006-05-03 19:07
(Received via mailing list)
On Thu, 4 May 2006, Peter Bailey wrote:

try

> require 'net/ftp'
> indexfiles = Dir.glob("*.pdf")
> indexfiles.each do |indexfile|
>  ftp = Net::FTP.open('mpc.bna.com') do |ftp|

ftp.passive = true

>  ftp.login('username','password')
>  ftp.chdir('/data/bnaindex')
>  ftp.putbinaryfile("indexfile")
>  end
> end

-a
B58c6eef325656d513d26e2c3ae6bfd9?d=identicon&s=25 Peter Bailey (peterbailey)
on 2006-05-03 21:03
unknown wrote:
> On Thu, 4 May 2006, Peter Bailey wrote:
>
> try
>
>> require 'net/ftp'
>> indexfiles = Dir.glob("*.pdf")
>> indexfiles.each do |indexfile|
>>  ftp = Net::FTP.open('mpc.bna.com') do |ftp|
>
> ftp.passive = true
>
>>  ftp.login('username','password')
>>  ftp.chdir('/data/bnaindex')
>>  ftp.putbinaryfile("indexfile")
>>  end
>> end
>
> -a

Thanks for your response. Unfortunately, it still didn't work. For the
time being, I've just re-done my script to exit out and execute a script
from another language.
481b8eedcc884289756246e12d1869c1?d=identicon&s=25 Francis Cianfrocca (Guest)
on 2006-05-03 21:08
(Received via mailing list)
Did you run a network snoop to see if the FTP session is even getting
out of
your machine?
4b174722d1b1a4bbd9672e1ab50c30a9?d=identicon&s=25 Ryan Leavengood (Guest)
on 2006-05-03 21:14
(Received via mailing list)
On 5/3/06, Peter Bailey <pbailey@bna.com> wrote:
>
> require 'net/ftp'
> indexfiles = Dir.glob("*.pdf")
> indexfiles.each do |indexfile|
>   ftp = Net::FTP.open('mpc.bna.com') do |ftp|
>   ftp.login('username','password')
>   ftp.chdir('/data/bnaindex')
>   ftp.putbinaryfile("indexfile")

I suppose no one has pointed out that the above line is probably a
bug. Here you are telling the FTP library to put a binary file called
indexfile, not using the contents of the variable indexfile. Therein
lies the problem, as far as I can see.

Regards,
Ryan
9358cc96c46055cd68d4a76a9aefe026?d=identicon&s=25 Daniel Harple (Guest)
on 2006-05-03 21:17
(Received via mailing list)
On May 3, 2006, at 5:19 PM, Peter Bailey wrote:

> require 'net/ftp'
> indexfiles = Dir.glob("*.pdf")
> indexfiles.each do |indexfile|
>   ftp = Net::FTP.open('mpc.bna.com') do |ftp|
>   ftp.login('username','password')
>   ftp.chdir('/data/bnaindex')
>   ftp.putbinaryfile("indexfile")
                        ^^^^^^^^^
                       you want indexfile, not "indexfile"
>   end
> end

Also, you are creating a new connection for every file. You want
something like:

require 'net/ftp'
Net::FTP.open('mpc.bna.com') do |ftp|
   ftp.login('username','password')
   ftp.chdir('/data/bnaindex')
   Dir.glob("*.pdf").each { |file| ftp.putbinaryfile(file) }
end

-- Daniel
B58c6eef325656d513d26e2c3ae6bfd9?d=identicon&s=25 Peter Bailey (peterbailey)
on 2006-05-03 22:20
Francis Cianfrocca wrote:
> Did you run a network snoop to see if the FTP session is even getting
> out of
> your machine?

I don't know of such a thing. But, I did do a regular command line ftp
(winxp) and it worked fine. Thanks.
B58c6eef325656d513d26e2c3ae6bfd9?d=identicon&s=25 Peter Bailey (peterbailey)
on 2006-05-03 22:23
Ryan Leavengood wrote:
> On 5/3/06, Peter Bailey <pbailey@bna.com> wrote:
>>
>> require 'net/ftp'
>> indexfiles = Dir.glob("*.pdf")
>> indexfiles.each do |indexfile|
>>   ftp = Net::FTP.open('mpc.bna.com') do |ftp|
>>   ftp.login('username','password')
>>   ftp.chdir('/data/bnaindex')
>>   ftp.putbinaryfile("indexfile")
>
> I suppose no one has pointed out that the above line is probably a
> bug. Here you are telling the FTP library to put a binary file called
> indexfile, not using the contents of the variable indexfile. Therein
> lies the problem, as far as I can see.
>
> Regards,
> Ryan

You mean, I shouldn't have it in quotes, right? Or, should I use
(#{indexfile})? I have been told in the past to use that #{
nomenclature. Now I see why. Thank you!
B58c6eef325656d513d26e2c3ae6bfd9?d=identicon&s=25 Peter Bailey (peterbailey)
on 2006-05-03 22:25
Daniel Harple wrote:
> On May 3, 2006, at 5:19 PM, Peter Bailey wrote:
>
>> require 'net/ftp'
>> indexfiles = Dir.glob("*.pdf")
>> indexfiles.each do |indexfile|
>>   ftp = Net::FTP.open('mpc.bna.com') do |ftp|
>>   ftp.login('username','password')
>>   ftp.chdir('/data/bnaindex')
>>   ftp.putbinaryfile("indexfile")
>                         ^^^^^^^^^
>                        you want indexfile, not "indexfile"
>>   end
>> end
>
> Also, you are creating a new connection for every file. You want
> something like:
>
> require 'net/ftp'
> Net::FTP.open('mpc.bna.com') do |ftp|
>    ftp.login('username','password')
>    ftp.chdir('/data/bnaindex')
>    Dir.glob("*.pdf").each { |file| ftp.putbinaryfile(file) }
> end
>
> -- Daniel


Thanks. I'll try this. The reason I was doing it for every file was
because, in my real, live file, I'm sending a notification e-mail for
each file sent, with the filename in the subject line. I suppose I could
still do that, after sending all the files en-masse. Just to a mail
"each" for each PDF.
481b8eedcc884289756246e12d1869c1?d=identicon&s=25 Francis Cianfrocca (Guest)
on 2006-05-03 22:29
(Received via mailing list)
Apart from the fact the Leavengood (upthread) has probably spotted your
problem, try ethereal on Windows if you're still having trouble. It'll
at
least tell you if your problem is local.
Bd0203dc8478deb969d72f52e741bd4f?d=identicon&s=25 Daniel Baird (Guest)
on 2006-05-04 02:13
(Received via mailing list)
On 5/4/06, Peter Bailey <pbailey@bna.com> wrote:
>
> You mean, I shouldn't have it in quotes, right? Or, should I use
> (#{indexfile})? I have been told in the past to use that #{
> nomenclature. Now I see why. Thank you!



The #{var} syntax is for embedding a variable in a string.

  str = "Hello #{username}, welcome to the Bat Cave."

if you're not in a string, don't use #{var}, the unadorned variable name
will give you the variable.

  say_hello_to(username)


Cheers

;Daniel
B58c6eef325656d513d26e2c3ae6bfd9?d=identicon&s=25 Peter Bailey (peterbailey)
on 2006-05-04 15:52
Francis Cianfrocca wrote:
> Apart from the fact the Leavengood (upthread) has probably spotted your
> problem, try ethereal on Windows if you're still having trouble. It'll
> at
> least tell you if your problem is local.

I've googled it and I'll download it. Thanks. But, I do know that many,
many files are going from my company to our printer, for printing, so, I
don't think it's a network issue. I just think that my RUBY is screwy.
B58c6eef325656d513d26e2c3ae6bfd9?d=identicon&s=25 Peter Bailey (peterbailey)
on 2006-05-04 15:53
Daniel Baird wrote:
> On 5/4/06, Peter Bailey <pbailey@bna.com> wrote:
>>
>> You mean, I shouldn't have it in quotes, right? Or, should I use
>> (#{indexfile})? I have been told in the past to use that #{
>> nomenclature. Now I see why. Thank you!
>
>
>
> The #{var} syntax is for embedding a variable in a string.
>
>   str = "Hello #{username}, welcome to the Bat Cave."
>
> if you're not in a string, don't use #{var}, the unadorned variable name
> will give you the variable.
>
>   say_hello_to(username)
>
>
> Cheers
>
> ;Daniel

Still now working. But, I appreciate very much your explanation of #{}.
It helps a lot.
This topic is locked and can not be replied to.