⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 07 - being an ftp client.rb

📁 O Reilly Ruby Cookbook source code
💻 RB
字号:
require 'net/ftp'ftp = Net::FTP.open('ftp.ibiblio.org') do |ftp|  ftp.login  ftp.chdir('pub/linux/')  ftp.list('*Linux*') { |file| puts file }  puts  puts 'Saving a text file to disk while processing it.'  ftp.gettextfile('How-do-I-get-Linux') { |line| puts "! #{line}" }  puts "Saved #{File.size 'How-do-I-get-Linux'} bytes."  puts  puts 'Saving a binary file to disk.'  ftp.getbinaryfile('INDEX.whole.gz')   puts "Saved #{File.size 'INDEX.whole.gz'} bytes."end# -rw-r--r--   1 (?)      users    16979001 Jan  1 11:31 00-find.Linux.gz# -rw-rw-r--   1 (?) admin          73 Mar  9  2001 How-do-I-get-Linux# Saving a text file to disk while processing it.# !# !   Browse to http://metalab.unc.edu/linux/HOWTO/Installation-HOWTO.html# !# Saved 73 bytes.# Saving a binary file to disk.# Saved 213507 bytes.#---ftp.login('leonardr', 'mypass')#---class Net::FTP  def processtextfile(remotefile)    retrlines('RETR ' + remotefile) { |line| yield line }  end  def processbinaryfile(remotefile, blocksize=DEFAULT_BLOCKSIZE)    retrbinary('RETR ' + remotefile, blocksize) { |data| yield data }  endend#---require 'net/ftp'Net::FTP.open('myisp.example.com') do |ftp|  ftp.login('leonardr', 'mypass')  ftp.chdir('public_html')  ftp.puttextfile('index.html')end#---

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -