Class: FTPUtils::FTPFile

Inherits:
Object
  • Object
show all
Defined in:
lib/ftputils/ftpfile.rb

Class Method Summary collapse

Class Method Details

.basename(path, suffix = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/ftputils/ftpfile.rb', line 4

def self.basename(path, suffix=nil)
  if ftp_uri = FTPUtils::FTPURI.parse(path)
    if suffix
      return ftp_uri.filename.gsub!(/#{suffix}\Z/,'')
    else
      return ftp_uri.filename
    end
  else
    if suffix
      return File.basename(path, suffix)
    else
      return File.basename(path)
    end
  end
end

.directory?(path) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ftputils/ftpfile.rb', line 20

def self.directory?(path)
  if ftp_uri = FTPUtils::FTPURI.parse(path)
    begin
      connection = FTPUtils::FTPConnection.connect(path)
      connection.chdir(ftp_uri.path)
      
      return true
    rescue Net::FTPPermError
      return false
    end
  else
    return File.directory? path
  end
end

.dirname(path) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/ftputils/ftpfile.rb', line 35

def self.dirname(path)
  if ftp_uri = FTPUtils::FTPURI.parse(path)
    return ftp_uri.dirname
  else
    return File.dirname(path)
  end
end

.exists?(path) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ftputils/ftpfile.rb', line 43

def self.exists?(path)
  if ftp_uri = FTPUtils::FTPURI.parse(path)
    connection = FTPUtils::FTPConnection.connect(path)
    connection.chdir ftp_uri.dirname
    if connection.size(ftp_uri.filename) > 0
      return true
    else
      return false
    end
  else
    return File.exists?(path)
  end
end

.expand_path(path) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/ftputils/ftpfile.rb', line 57

def self.expand_path(path)
  if ftp_uri = FTPUtils::FTPURI.parse(path)
    return path
  else
    return File.expand_path(path)
  end
end

.file?(path) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/ftputils/ftpfile.rb', line 65

def self.file?(path)
  if ftp_uri = FTPUtils::FTPURI.parse(path)
    connection = FTPUtils::FTPConnection.connect(path)
    connection.chdir(ftp_uri.dirname)

    begin
      connection.size(ftp_uri.filename)
      return true
    rescue Net::FTPPermError
      return false
    end
  else
    return File.file? path
  end
end

.mtime(path) ⇒ Object



81
82
83
84
85
86
87
88
89
90
# File 'lib/ftputils/ftpfile.rb', line 81

def self.mtime(path)
  if ftp_uri = FTPUtils::FTPURI.parse(path)
    connection = FTPUtils::FTPConnection.connect(path)
    connection.chdir(ftp_uri.dirname)

    return connection.mtime(ftp_uri.filename)
  else
    return File.mtime path
  end
end

.relative_path(path) ⇒ Object



92
93
94
95
96
97
98
# File 'lib/ftputils/ftpfile.rb', line 92

def self.relative_path(path)
  if ftp_uri = FTPUtils::FTPURI.parse(path)
    return ftp_uri.path
  else
    return nil
  end
end