001 002 package railo.runtime.net.ftp; 003 004 005 006 007 /** 008 * 009 */ 010 public final class FTPConnectionImpl implements FTPConnection { 011 012 private String name; 013 private String server; 014 private String username; 015 private String password; 016 private int port; 017 private int timeout; 018 private short transferMode; 019 private boolean passive; 020 private String proxyserver; 021 private int proxyport; 022 private String proxyuser; 023 private String proxypassword; 024 025 /** 026 * @param name 027 * @param server 028 * @param username 029 * @param password 030 * @param port 031 * @param timeout 032 * @param transferMode 033 * @param passive 034 * @param proxyserver 035 */ 036 public FTPConnectionImpl(String name, String server, String username, String password,int port, int timeout, short transferMode,boolean passive, 037 String proxyserver,int proxyport,String proxyuser, String proxypassword) { 038 this.name=name==null?null:name.toLowerCase().trim(); 039 this.server=server; 040 this.username=username; 041 this.password=password; 042 this.port=port; 043 this.timeout=timeout; 044 this.transferMode=transferMode; 045 this.passive=passive; 046 047 this.proxyserver=proxyserver; 048 this.proxyport=proxyport; 049 this.proxyuser=proxyuser; 050 this.proxypassword=proxypassword; 051 } 052 /** 053 * @see railo.runtime.net.ftp.FTPConnection#getName() 054 */ 055 public String getName() { 056 return name; 057 } 058 /** 059 * @see railo.runtime.net.ftp.FTPConnection#getPassword() 060 */ 061 public String getPassword() { 062 return password; 063 } 064 /** 065 * @see railo.runtime.net.ftp.FTPConnection#getServer() 066 */ 067 public String getServer() { 068 return server; 069 } 070 /** 071 * @see railo.runtime.net.ftp.FTPConnection#getUsername() 072 */ 073 public String getUsername() { 074 return username; 075 } 076 /** 077 * @see railo.runtime.net.ftp.FTPConnection#hasLoginData() 078 */ 079 public boolean hasLoginData() { 080 return server!=null;// && username!=null && password!=null; 081 } 082 /** 083 * @see railo.runtime.net.ftp.FTPConnection#hasName() 084 */ 085 public boolean hasName() { 086 return name!=null; 087 } 088 /** 089 * @see railo.runtime.net.ftp.FTPConnection#getPort() 090 */ 091 public int getPort() { 092 return port; 093 } 094 /** 095 * @see railo.runtime.net.ftp.FTPConnection#getTimeout() 096 */ 097 public int getTimeout() { 098 return timeout; 099 } 100 /** 101 * @see railo.runtime.net.ftp.FTPConnection#getTransferMode() 102 */ 103 public short getTransferMode() { 104 return transferMode; 105 } 106 107 108 public void setTransferMode(short transferMode) { 109 this.transferMode=transferMode; 110 } 111 112 /** 113 * @see railo.runtime.net.ftp.FTPConnection#isPassive() 114 */ 115 public boolean isPassive() { 116 return passive; 117 } 118 /** 119 * @see railo.runtime.net.ftp.FTPConnection#loginEquals(railo.runtime.net.ftp.FTPConnection) 120 */ 121 public boolean loginEquals(FTPConnection conn) { 122 return 123 server.equalsIgnoreCase(conn.getServer()) && 124 username.equals(conn.getUsername()) && 125 password.equals(conn.getPassword()); 126 } 127 128 /** 129 * @see railo.runtime.net.ftp.FTPConnection#getProxyPassword() 130 */ 131 public String getProxyPassword() { 132 return proxypassword; 133 } 134 135 /** 136 * @see railo.runtime.net.ftp.FTPConnection#getProxyPort() 137 */ 138 public int getProxyPort() { 139 return proxyport; 140 } 141 142 /** 143 * @see railo.runtime.net.ftp.FTPConnection#getProxyServer() 144 */ 145 public String getProxyServer() { 146 return proxyserver; 147 } 148 149 /** 150 * @see railo.runtime.net.ftp.FTPConnection#getProxyUser() 151 */ 152 public String getProxyUser() { 153 return proxyuser; 154 } 155 156 public boolean equal(Object o){ 157 if(!(o instanceof FTPConnection)) return false; 158 FTPConnection other=(FTPConnection) o; 159 160 if(neq(other.getPassword(),getPassword())) return false; 161 if(neq(other.getProxyPassword(),getProxyPassword())) return false; 162 if(neq(other.getProxyServer(),getProxyServer())) return false; 163 if(neq(other.getProxyUser(),getProxyUser())) return false; 164 if(neq(other.getServer(),getServer())) return false; 165 if(neq(other.getUsername(),getUsername())) return false; 166 167 if(other.getPort()!=getPort()) return false; 168 if(other.getProxyPort()!=getProxyPort()) return false; 169 //if(other.getTimeout()!=getTimeout()) return false; 170 if(other.getTransferMode()!=getTransferMode()) return false; 171 172 return true; 173 } 174 175 private boolean neq(String left, String right) { 176 if(left==null) left=""; 177 if(right==null) right=""; 178 179 return !left.equals(right); 180 } 181 182 }