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 @Override 053 public String getName() { 054 return name; 055 } 056 @Override 057 public String getPassword() { 058 return password; 059 } 060 @Override 061 public String getServer() { 062 return server; 063 } 064 @Override 065 public String getUsername() { 066 return username; 067 } 068 @Override 069 public boolean hasLoginData() { 070 return server!=null;// && username!=null && password!=null; 071 } 072 @Override 073 public boolean hasName() { 074 return name!=null; 075 } 076 @Override 077 public int getPort() { 078 return port; 079 } 080 @Override 081 public int getTimeout() { 082 return timeout; 083 } 084 @Override 085 public short getTransferMode() { 086 return transferMode; 087 } 088 089 090 public void setTransferMode(short transferMode) { 091 this.transferMode=transferMode; 092 } 093 094 @Override 095 public boolean isPassive() { 096 return passive; 097 } 098 @Override 099 public boolean loginEquals(FTPConnection conn) { 100 return 101 server.equalsIgnoreCase(conn.getServer()) && 102 username.equals(conn.getUsername()) && 103 password.equals(conn.getPassword()); 104 } 105 106 @Override 107 public String getProxyPassword() { 108 return proxypassword; 109 } 110 111 @Override 112 public int getProxyPort() { 113 return proxyport; 114 } 115 116 @Override 117 public String getProxyServer() { 118 return proxyserver; 119 } 120 121 @Override 122 public String getProxyUser() { 123 return proxyuser; 124 } 125 126 public boolean equal(Object o){ 127 if(!(o instanceof FTPConnection)) return false; 128 FTPConnection other=(FTPConnection) o; 129 130 if(neq(other.getPassword(),getPassword())) return false; 131 if(neq(other.getProxyPassword(),getProxyPassword())) return false; 132 if(neq(other.getProxyServer(),getProxyServer())) return false; 133 if(neq(other.getProxyUser(),getProxyUser())) return false; 134 if(neq(other.getServer(),getServer())) return false; 135 if(neq(other.getUsername(),getUsername())) return false; 136 137 if(other.getPort()!=getPort()) return false; 138 if(other.getProxyPort()!=getProxyPort()) return false; 139 //if(other.getTimeout()!=getTimeout()) return false; 140 if(other.getTransferMode()!=getTransferMode()) return false; 141 142 return true; 143 } 144 145 private boolean neq(String left, String right) { 146 if(left==null) left=""; 147 if(right==null) right=""; 148 149 return !left.equals(right); 150 } 151 152 }