This repository has been archived by the owner on Jul 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from mzahir/feature/ftp
Add FTP module
- Loading branch information
Showing
10 changed files
with
526 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
module Lumberg | ||
module Cpanel | ||
class Ftp < Base | ||
def self.api_module; "Ftp"; end | ||
|
||
# Public: List FTP accounts associated with the authenticated user's account | ||
# | ||
# options - Hash options for API call params (default: {}): | ||
# :include_acct_types - specify which FTP account types to include | ||
# :skip_acct_types - specify which FTP account types to exclude | ||
# | ||
# Returns Hash API response. | ||
def list_ftp(options = {}) | ||
perform_request({ | ||
api_function: "listftp" | ||
}.merge(options)) | ||
end | ||
|
||
# Public: Retrieve a list of FTP sessions associated with the account | ||
# | ||
# Returns Hash API response. | ||
def list_ftp_sessions(options = {}) | ||
perform_request({ | ||
api_function: "listftpsessions" | ||
}.merge(options)) | ||
end | ||
|
||
# Public: Generate a list of FTP accounts associated with a cPanel account | ||
# The list will contain each account's disk information | ||
# | ||
# options - Hash options for API call params (default: {}): | ||
# :dirhtml - prepend the 'dir' return variable with a URL | ||
# :include_acct_types - specify which FTP account types to include | ||
# :skip_acct_types - specify which FTP account types to exclude | ||
# | ||
# Returns Hash API response. | ||
def list_ftp_with_disk(options = {}) | ||
perform_request({ | ||
api_function: "listftpwithdisk" | ||
}.merge(options)) | ||
end | ||
|
||
# Public: Change an FTP account's password | ||
# | ||
# options - Hash options for API call params (default: {}): | ||
# :user - The username portion of the FTP account | ||
# :pass - The new password for the FTP account | ||
# | ||
# Returns Hash API response. | ||
def passwd(options = {}) | ||
perform_request({ | ||
api_function: "passwd" | ||
}.merge(options)) | ||
end | ||
|
||
# Public: Add a new FTP account | ||
# | ||
# options - Hash options for API call params (default: {}): | ||
# :user - The username portion of the new FTP account, without the domain | ||
# :pass - The password for the new FTP account | ||
# :quota - The new FTP account's quota. The default, 0, indicates that | ||
# the account will not use a quota. | ||
# :homedir - The path to the FTP account's root directory. This value | ||
# should be relative to the account's home directory | ||
# | ||
# Returns Hash API response. | ||
def add_ftp(options = {}) | ||
perform_request({ | ||
api_function: "addftp" | ||
}.merge(options)) | ||
end | ||
|
||
# Public: Change an FTP account's quota | ||
# | ||
# options - Hash options for API call params (default: {}): | ||
# :user - The username portion of the FTP account | ||
# :quota - The new quota (in megabytes) for the FTP account | ||
# | ||
# Returns Hash API response. | ||
def set_quota(options = {}) | ||
perform_request({ | ||
api_function: "setquota" | ||
}.merge(options)) | ||
end | ||
|
||
# Public: Delete an FTP account | ||
# | ||
# options - Hash options for API call params (default: {}): | ||
# :user - The name of the account to be removed | ||
# :destroy - A boolean value that indicates whether or not the FTP account's | ||
# home directory should also be deleted | ||
# | ||
# Returns Hash API response. | ||
def del_ftp(options = {}) | ||
perform_request({ | ||
api_function: "delftp" | ||
}.merge(options)) | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
require "spec_helper" | ||
|
||
module Lumberg | ||
describe Cpanel::Ftp do | ||
let(:server) { Whm::Server.new(host: @whm_host, hash: @whm_hash) } | ||
let(:api_username) { "lumberg" } | ||
|
||
let(:ftp) do | ||
described_class.new( | ||
server: server, | ||
api_username: api_username | ||
) | ||
end | ||
|
||
describe "#list_ftp" do | ||
use_vcr_cassette("cpanel/ftp/listftp") | ||
|
||
it "lists ftp accounts associated to the account" do | ||
ftp.list_ftp[:params][:data][0][:user].should eq("hello") | ||
end | ||
end | ||
|
||
describe "#list_ftp_sessions" do | ||
use_vcr_cassette("cpanel/ftp/listftpsessions") | ||
|
||
it "lists ftp sessions associated to the account" do | ||
ftp.list_ftp_sessions[:params][:data][0][:status].should eq("IDLE") | ||
end | ||
end | ||
|
||
describe "#list_ftp_with_disk" do | ||
use_vcr_cassette("cpanel/ftp/listftpwithdisk") | ||
|
||
it "lists ftp accounts with disk information" do | ||
ftp.list_ftp_with_disk[:params][:data][0][:_diskused].should eq("0") | ||
end | ||
end | ||
|
||
describe "#add_ftp" do | ||
use_vcr_cassette("cpanel/ftp/addftp") | ||
|
||
it "creates the account" do | ||
ftp.add_ftp(user: 'bob', pass: 'boo')[:params][:data][0][:reason].should eq("OK") | ||
end | ||
end | ||
|
||
describe "#passwd" do | ||
use_vcr_cassette("cpanel/ftp/passwd") | ||
|
||
it "changes the password of the account" do | ||
ftp.passwd(user: 'bob', pass: 'boo')[:params][:data][0][:reason].should eq("OK") | ||
end | ||
end | ||
|
||
describe "#setquota" do | ||
use_vcr_cassette("cpanel/ftp/setquota") | ||
|
||
it "sets a quota for the account" do | ||
ftp.set_quota(user: 'bob', quota: '100')[:params][:data][0][:reason].should eq("OK") | ||
end | ||
end | ||
|
||
describe "#del_ftp" do | ||
use_vcr_cassette("cpanel/ftp/delftp") | ||
|
||
it "removes the account" do | ||
ftp.del_ftp(user: 'bob', destroy: '1')[:params][:data][0][:reason].should eq("OK") | ||
end | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.