Class: Net::FTP

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

Instance Method Summary collapse

Instance Method Details

#mkdir_p(dir) ⇒ Object

Net::FTP extension

Like FileUtils.mkdir_p but for Net::FTP



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/syncftp.rb', line 67

def mkdir_p( dir )
  path = dir.split( "/" )
  mkpath = path.shift
  begin
    mkdir( mkpath ) unless mkpath == ""
  rescue Net::FTPPermError => e
    raise Net::FTPPermError, e.message, caller unless remote_dir_exist?(mkpath)
  end
  path.each do |d|
    mkpath = [mkpath, d].join( "/" )
    begin
      mkdir( mkpath )
    rescue Net::FTPPermError => e
      raise Net::FTPPermError, e.message, caller unless remote_dir_exist?(mkpath)
    end
  end
end

#remote_dir_exist?(dir) ⇒ Boolean

Net::FTP extension

Check if the dir exist on the remote FTP server

Returns:

  • (Boolean)


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/syncftp.rb', line 45

def remote_dir_exist?( dir )
  path = dir.split( "/" )
  find = path.pop
  path = path.join( "/" )
  path = "." if path == ""
  altdir = dir
  altdir = dir[2..-1] if dir[0,2] == "./"
  
  return true if dir == "."
  
  begin
    nlst( path ).include?( find ) or nlst( path ).include?( dir ) or nlst( path ).include?( altdir )
  rescue Net::FTPTempError
    return false
  end
end

#remote_file_exist?(file) ⇒ Boolean

Net::FTP extension

Check if the file exist on the remote FTP server

Returns:

  • (Boolean)


36
37
38
# File 'lib/syncftp.rb', line 36

def remote_file_exist?( file )
  ls( file ).size != 0
end