Problems ftp'ing with RUBY

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

On Thu, 4 May 2006, Peter B. 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

unknown wrote:

On Thu, 4 May 2006, Peter B. 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.

Did you run a network snoop to see if the FTP session is even getting
out of
your machine?

On 5/3/06, Peter B. [email protected] 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

Francis C. 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.

On May 3, 2006, at 5:19 PM, Peter B. 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

Ryan L. wrote:

On 5/3/06, Peter B. [email protected] 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!

Daniel H. wrote:

On May 3, 2006, at 5:19 PM, Peter B. 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.

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.

On 5/4/06, Peter B. [email protected] 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

Francis C. 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.

Daniel B. wrote:

On 5/4/06, Peter B. [email protected] 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.