iam_ftp 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +3 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +45 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/iam_ftp.gemspec +23 -0
- data/lib/iam_ftp/version.rb +5 -0
- data/lib/iam_ftp.rb +101 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e0ee32c5c4f133c0b7b05f6021999e347eff6af6
|
4
|
+
data.tar.gz: 308fb435ed316f25e59ece91a43714ee450a55b9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7f0bd94924077a33b1c664e8f6e0675d4087967bea4a3cf402b386d9783cec2e5efcc6c785055fe823b713bae85a549c5cb49980e5edc035b85ba9f4a8435ff4
|
7
|
+
data.tar.gz: 2af5798796f365163f84b5456f7fd2742b6128ad15d454bf57da82df722c6b6667cfd967abc0a1a835f9fd96cb75f8fb99a4290819400a2d87672792cb6f6043
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 TODO: Write your name
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Iam::Ftp
|
2
|
+
|
3
|
+
Thanks to Ruby’s 'net/ftp' library this gem would come in handy if you want to upload files or directories to an remote server with FTP.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install iam_ftp
|
8
|
+
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
require 'iam_ftp'
|
13
|
+
|
14
|
+
to initialize
|
15
|
+
|
16
|
+
connect = IamFtp::FtpCalls.new({:ftp_host => "ftp.iamfree.com", :ftp_username => "me@iamfree.com", :ftp_password => "i dont know"})
|
17
|
+
|
18
|
+
To upload an entire directory to server FTP
|
19
|
+
|
20
|
+
connect.upload_directory_to_ftp_server("/Users/me/Documents/work/iamnotfree/my-site/", "/home/www/")
|
21
|
+
|
22
|
+
|
23
|
+
If the server is a shared host like Godaddy.com hosting: leave second parameter blank
|
24
|
+
|
25
|
+
connect.upload_directory_to_ftp_server("/Users/me/Documents/work/iamnotfree/my-site/", "")
|
26
|
+
|
27
|
+
|
28
|
+
To upload a file one by one(firsly the directory, then the remote directory, then the file name)
|
29
|
+
|
30
|
+
connect.upload_file_to_ftp_server("/Users/me/Documents/work/iamnotfree/my-site", "", "/Users/me/Documents/work/iamnotfree/my-site/messages.html")
|
31
|
+
|
32
|
+
|
33
|
+
If it is too hard to type the file path. Just locate the file in "finder" and drag it to your terminal. That would get your file path on to the terminal.
|
34
|
+
|
35
|
+
To list all the files in your FTP server
|
36
|
+
|
37
|
+
connect.list_all_files
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
1. Fork it ( https://github.com/iamfree-com/iam_ftp/fork )
|
42
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
43
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
44
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
45
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "iam_ftp"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/iam_ftp.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'iam_ftp/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "iam_ftp"
|
8
|
+
spec.version = IamFtp::VERSION
|
9
|
+
spec.authors = ["anthony de silva"]
|
10
|
+
spec.email = ["anthony @ iamfree.com"]
|
11
|
+
spec.summary = %q{A Ruby FTP client}
|
12
|
+
spec.description = %q{I think i can upload files to an FTP server, list all files and download files from FTP server}
|
13
|
+
spec.homepage = "https://github.com/iamfree-com/iam_ftp"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
data/lib/iam_ftp.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'net/ftp'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
|
5
|
+
module IamFtp
|
6
|
+
|
7
|
+
class FtpCalls
|
8
|
+
|
9
|
+
attr_accessor :ftp_host, :ftp_username, :ftp_password
|
10
|
+
|
11
|
+
class << self
|
12
|
+
attr_accessor :logger
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(ftp_info_hash)
|
16
|
+
@ftp_host = ftp_info_hash[:ftp_host].to_s
|
17
|
+
@ftp_username = ftp_info_hash[:ftp_username].to_s
|
18
|
+
@ftp_password = ftp_info_hash[:ftp_password].to_s
|
19
|
+
@connection = nil
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def ftp_connect
|
24
|
+
@connection = Net::FTP.new(ftp_host)
|
25
|
+
@connection.passive =true
|
26
|
+
@connection.login(ftp_username, ftp_password)
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def ftp_close
|
31
|
+
puts "Connection closing.."
|
32
|
+
@connection.close
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def list_all_files
|
37
|
+
|
38
|
+
Net::FTP.open(ftp_host) do |ftp|
|
39
|
+
ftp.login(ftp_username, ftp_password )
|
40
|
+
ftp.passive = true
|
41
|
+
a = ftp.nlst
|
42
|
+
b = ftp.nlst('**/*.*')
|
43
|
+
c = ftp.nlst('**/**/*.*')
|
44
|
+
d = ftp.nlst('**/**/**/*.*')
|
45
|
+
e = ftp.nlst('**/**/**/**/*.*')
|
46
|
+
|
47
|
+
|
48
|
+
ftp.close
|
49
|
+
|
50
|
+
file_list = a+ b + c + d + e
|
51
|
+
file_list
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
def is_ftp_file?(ftp, file_name)
|
57
|
+
ftp.chdir(file_name)
|
58
|
+
ftp.chdir('..')
|
59
|
+
false
|
60
|
+
|
61
|
+
rescue
|
62
|
+
|
63
|
+
true
|
64
|
+
end
|
65
|
+
|
66
|
+
def get_ready_and_upload_the_file(local_file_path, remote_file_path, filename)
|
67
|
+
filename.gsub!("#{local_file_path}/", '')
|
68
|
+
local = File.join local_file_path, filename
|
69
|
+
remote = "#{remote_file_path}/#{filename}".gsub(/\/+/, '/')
|
70
|
+
|
71
|
+
if File.directory?(local)
|
72
|
+
@connection.mkdir remote rescue Net::FTPPermError
|
73
|
+
puts "Created Remote Directory #{local}"
|
74
|
+
elsif File.file?(local)
|
75
|
+
@connection.putbinaryfile local, remote
|
76
|
+
puts "Pushed file #{remote}"
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
def upload_directory_to_ftp_server(local_file_path, remote_file_path)
|
83
|
+
ftp_connect
|
84
|
+
|
85
|
+
Dir.glob(File.join(local_file_path, '**', '*')) do |filename|
|
86
|
+
get_ready_and_upload_the_file(local_file_path, remote_file_path, filename)
|
87
|
+
end
|
88
|
+
|
89
|
+
ftp_close
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
def upload_file_to_ftp_server(local_file_path, remote_file_path, filename)
|
95
|
+
get_ready_and_upload_the_file(local_file_path, remote_file_path, filename)
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: iam_ftp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- anthony de silva
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: I think i can upload files to an FTP server, list all files and download
|
42
|
+
files from FTP server
|
43
|
+
email:
|
44
|
+
- anthony @ iamfree.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- ".travis.yml"
|
51
|
+
- CODE_OF_CONDUCT.md
|
52
|
+
- Gemfile
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- bin/console
|
57
|
+
- bin/setup
|
58
|
+
- iam_ftp.gemspec
|
59
|
+
- lib/iam_ftp.rb
|
60
|
+
- lib/iam_ftp/version.rb
|
61
|
+
homepage: https://github.com/iamfree-com/iam_ftp
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 2.4.5
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: A Ruby FTP client
|
85
|
+
test_files: []
|