Problems ftp'ing with RUBY


#1

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


#2

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


#3

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.


#4

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


#5

On 5/3/06, Peter B. removed_email_address@domain.invalid 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


#6

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.


#7

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


#8

Ryan L. wrote:

On 5/3/06, Peter B. removed_email_address@domain.invalid 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!


#9

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.


#10

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.


#11

On 5/4/06, Peter B. removed_email_address@domain.invalid 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


#12

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.


#13

Daniel B. wrote:

On 5/4/06, Peter B. removed_email_address@domain.invalid 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.