001 package railo.commons.io.res.type.ftp; 002 003 import railo.commons.lang.StringUtil; 004 005 public final class FTPConnectionData { 006 007 public String username=""; 008 public String password=""; 009 public String host="localhost"; 010 public int port=0; 011 012 private String proxyserver; 013 private int proxyport; 014 private String proxyuser; 015 private String proxypassword; 016 017 018 public String load(String path) { 019 username=""; 020 password=""; 021 host=null; 022 port=21; 023 // TODO impl proxy 024 025 int atIndex=path.indexOf('@'); 026 int slashIndex=path.indexOf('/'); 027 if(slashIndex==-1){ 028 slashIndex=path.length(); 029 path+="/"; 030 } 031 int index; 032 033 // username/password 034 if(atIndex!=-1) { 035 index=path.indexOf(':'); 036 if(index!=-1 && index<atIndex) { 037 username=path.substring(0,index); 038 password=path.substring(index+1,atIndex); 039 } 040 else username=path.substring(0,atIndex); 041 } 042 // host port 043 if(slashIndex>atIndex+1) { 044 index=path.indexOf(':',atIndex+1); 045 if(index!=-1 && index>atIndex && index<slashIndex) { 046 host=path.substring(atIndex+1,index); 047 port=Integer.parseInt(path.substring(index+1,slashIndex)); 048 } 049 else host=path.substring(atIndex+1,slashIndex); 050 } 051 //if(slashIndex==-1)return "/"; 052 return path.substring(slashIndex); 053 } 054 055 056 057 @Override 058 public String toString() { 059 return "username:"+username+";password:"+password+";hostname:"+host+";port:"+port; 060 } 061 062 063 064 public String key() { 065 if(StringUtil.isEmpty(username)) 066 return host+_port(); 067 return username+":"+password+"@"+host+_port(); 068 } 069 070 071 072 private String _port() { 073 if(port>0) return ":"+port; 074 return ""; 075 } 076 077 078 079 public boolean hasProxyData() { 080 return getProxyserver()!=null; 081 } 082 083 084 085 /** 086 * @return the proxypassword 087 */ 088 public String getProxypassword() { 089 return proxypassword; 090 } 091 092 093 094 /** 095 * @return the proxyport 096 */ 097 public int getProxyport() { 098 return proxyport; 099 } 100 101 102 103 /** 104 * @return the proxyserver 105 */ 106 public String getProxyserver() { 107 return proxyserver; 108 } 109 110 111 112 /** 113 * @return the proxyuser 114 */ 115 public String getProxyuser() { 116 return proxyuser; 117 } 118 @Override 119 public boolean equals(Object obj) { 120 if(this==obj)return true; 121 if(!(obj instanceof FTPConnectionData)) return false; 122 return key().equals(((FTPConnectionData)obj).key()); 123 } 124 }