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
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.
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.
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
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!
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.
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.
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.
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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.