Created
July 21, 2015 03:37
-
-
Save Youngv/205861588ec843c6de84 to your computer and use it in GitHub Desktop.
通过FTP的方式把本地的图片上传到又拍云的脚本。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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