alcina
September 24, 2013, 1:00pm
1
Hi.
I have started to introduce the Net::FTP function to download something
from our FTP server, and wanted to introduce error handling.
Code is:
while @try < 6 do
#login to FTP Server, download latest seeding list & upload latest
seeding reports
ftp=Net::FTP.new
ftp.connect(“",21)
ftp.login(user=" *”,password="*********")
ftp.chdir(@remotedirectory )
ftp.get(@remotedirectory+@seedinglistname,@seedinglistname ,1024)
#upload latest seeding log…
#ftp .put("*********",@remotedirectory+"*********",1024)
ftp.close
puts “FTP activity successful on attempt #{@try }”
rescue Net::FTPError
@try = @try+1
next
end
I get the following error:
syntax error, unexpected keyword_rescue, expecting keyword_end
rescue Net::FTPError
I have copied the syntax from another while loop that is working, so not
sure why this isnt working.
Any help would be appreciated.
Thanks
On Tue, Sep 24, 2013 at 1:00 PM, Graeme H. [email protected]
wrote:
ftp=Net::FTP.new
@try = @try+1
Any help would be appreciated.
Just look at the syntax:
Programming Ruby: The Pragmatic Programmer's Guide
Kind regards
robert
Thanks both.
Im quite new to ruby programming, so failing to understand i think… A
bit more information on whats going wrong would help me understand.
In essence, I want the code to run in a loop and if there are any
errors/exceptions, to try again for a max of 5 times before giving up.
I think the part you’re missing is that “begin, rescue, end” blocks are
separate from “while” blocks.
On Tue, Sep 24, 2013 at 1:34 PM, Graeme H. [email protected]
wrote:
Thanks both.
Im quite new to ruby programming, so failing to understand i think… A
bit more information on whats going wrong would help me understand.
It’s purely a syntax issue as the error message indicates.
In essence, I want the code to run in a loop and if there are any
errors/exceptions, to try again for a max of 5 times before giving up.
Did you check link I gave before? I blogged about begin end from a
functional point of view a while ago:
http://blog.rubybestpractices.com/posts/rklemme/003-The_Universe_between_begin_and_end.html
Cheers
robert
Thanks guys, school boy error.
Didn’t have “begin” inside the while loop. Ill now know for next time!
On Sep 24, 2013, at 8:48 AM, Graeme H. [email protected] wrote:
Im using “File.rename @localdirectory+@seedinglistname,
@backuplocaldirectory+@seedinglistname” to move the file…
Take a full read through the File, Dir, and FileUtils classes/modules to
see about working with the file system. Some methods you’ll want to make
note of include exist? directory? writable? and a few others. Do also
look at the Pathname module as is it somewhat of a superset of the
previous 3.
Thanks for your help!
–
Posted via http://www.ruby-forum.com/ .
Class: File (Ruby 2.0.0)
Class: Dir (Ruby 2.0.0)
http://ruby-doc.com/stdlib-2.0/libdoc/fileutils/rdoc/FileUtils.html
Class: Pathname (Ruby 2.0.0)
Guys,
Got another issue, I want to move the local copy of the file its
downloading to a backup folder prior to the FTP download.
Currently, if the file doesn’t exist, then its falling over using
“Errno::ENOENT”.
How do I deal with this? I want the download to continue as it will
create the missing file during the download.
Im using “File.rename @localdirectory+@seedinglistname,
@backuplocaldirectory+@seedinglistname” to move the file…
Thanks for your help!