xiaopei的博客

--好好学习,天天向上

用户操作
[即时聊天] [发私信] [加为好友]
xiaopeiID:hxxiaopei
20610次访问,排名5811好友0人,关注者0
hxxiaopei的文章
原创 44 篇
翻译 0 篇
转载 13 篇
评论 5 篇
xiaopei的公告
-今年是菜鸟,明年成大牛- It is about Computer Science Technology
最近评论
lijing00333:很牛嘛
wenjie:baidu下yum源设置,没想到baidu到师兄你这了 挖哈哈~
xiaopei:所需要的头文件 sstream
InterMa:链接改好了,我也不知道这个tips,同学习,hoho
文章分类
收藏
    相册
    兄弟
    Dave chen
    InterMa
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创  使用ruby写了一个根据ftp服务器列表自动遍历所有服务器查找对应的东东收藏

    新一篇: 大家好~! | 旧一篇: RUBY的优点和缺点

    前在ftp上下载一个东西,需要查找很多ftp-server,累~今日学习ruby,使用ruby写了 一个对应给定的ftp_list和需要查找的东东,比如lost 越狱等,遍历ftp_list里面的所有服务器,如果找到,打印服务器名和对应的路径。不过感觉效率不是很好,高手完善一下
    require "net/ftp"
    class FTPDownload
    def initialize(ip_address,user,pw,port=21)
    puts ip_address.class,user,pw
    @ip_address=ip_address
    @user=user
    @pw=pw
    @port=port
    end
    def login?
    begin
    @ftp=Net::FTP.new(@ip_address)
    @ftp.login(@user,@pw)
    return true
    rescue
    return false
    end
    end
    def find_wanted(re)
    father_dir=""
    array_list=[]
    begin
    array = @ftp.list
    array.each do |file|
    if re.match(file) != nil
    puts @ftp.pwd
    puts "match"
    return true

    else
    if file[0]==100 #目录
    str=file.split(/\s*\s/)
    if str[str.length-1] !="." && str[str.length-1]!=".."
    new_dir = father_dir + "/" + str[str.length-1]
    array_list << new_dir
    end
    end
    end


    end
    next_dir=array_list.shift
    father_dir=next_dir
    begin
    @ftp.chdir(next_dir)
    rescue
    "can not change directory"
    end
    end until array_list.empty?
    end
    def close
    @ftp.close
    end
    end
    ADD=[]
    IO.foreach("ftpAddress") do|address|
    addr=address.split("\s")
    ADD << addr
    end
    re = Regexp.new("nfo")#需要查找的关键字
    ADD.each do |addr|
    printf addr[0], addr[1],addr[2]
    ftp=FTPDownload.new(addr[0],addr[1],addr[2])
    if ftp.login?
    ftp.find_wanted(re)
    ftp.close
    else
    puts "can not login"
    end
    end

    发表于 @ 2007年04月05日 16:08:00|评论(loading...)|编辑

    新一篇: 大家好~! | 旧一篇: RUBY的优点和缺点

    评论

    #lijing00333 发表于2008-06-13 17:17:37  IP: 202.165.107.*
    很牛嘛
    发表评论  


    当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
    Csdn Blog version 3.1a
    Copyright © xiaopei