Skip to content

Instantly share code, notes, and snippets.

@Youngv
Created July 21, 2015 03:37
Show Gist options
  • Save Youngv/205861588ec843c6de84 to your computer and use it in GitHub Desktop.
Save Youngv/205861588ec843c6de84 to your computer and use it in GitHub Desktop.
通过FTP的方式把本地的图片上传到又拍云的脚本。
#!/usr/bin/ruby
# encoding: utf-8
require 'uri'
require 'net/ftp'
def send_to_ftp(sourcefile, host, username, password)
uri = URI.parse("ftp://" + host)
ftp = Net::FTP.new
ftp.connect(uri.host, uri.port)
ftp.passive = true
ftp.login(username, password)
ftp.chdir(uri.path)
ftp.putbinaryfile(sourcefile)
ftp.close
puts "图片上传成功!"
rescue Exception => err
puts err.message
end
sourcefile = "someone.png"
host = "v1.ftp.upyun.com/dir"
username = "username"
password = "password"
send_to_ftp(sourcefile, host, username, password)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment