1 16 17 package net.sf.jftp.net; 19 20 import net.sf.jftp.JFtp; 21 import net.sf.jftp.config.Settings; 22 import net.sf.jftp.gui.tasks.LastConnections; 23 import net.sf.jftp.system.logging.Log; 24 25 26 public class StartConnection 32 { 33 public static FtpConnection con = null; 34 public static com.sshtools.j2ssh.configuration.SshConnectionProperties properties = new com.sshtools.j2ssh.configuration.SshConnectionProperties(); 35 public static String keyfile = null; 36 37 public static void setSshProperties(com.sshtools.j2ssh.configuration.SshConnectionProperties props) 38 { 39 properties = props; 40 } 41 42 public static void setSshKeyfile(String file) 43 { 44 keyfile = file; 45 } 46 47 public static boolean startCon(String protocol, String htmp, String utmp, 58 String ptmp, int potmp, String dtmp, 59 boolean useLocal) 60 { 61 String conType; 68 String [] searchValue = new String [JFtp.CONNECTION_DATA_LENGTH]; 69 70 Integer potmpInt = new Integer (potmp); 71 72 String potmpString = potmpInt.toString(); 73 String useLocalString = new String ("false"); 74 75 if(useLocal) 76 { 77 useLocalString = "true"; 78 } 79 80 if(protocol.equals("FTP")) 82 { 83 86 } 87 else if(protocol.equals("SFTP")) 88 { 89 SftpConnection con; 90 91 con = new SftpConnection(properties, keyfile); 94 95 if(con.login(utmp, ptmp)) 100 { 101 if(useLocal) 102 { 103 JFtp.statusP.jftp.addLocalConnection(htmp, con); 104 } 105 else 106 { 107 JFtp.statusP.jftp.addConnection(htmp, con); 108 } 109 110 if(con.chdir(con.getPWD()) || con.chdir("/")) 112 { 113 ; 114 } 115 116 searchValue[0] = "SFTP"; 118 searchValue[1] = htmp; 119 searchValue[2] = utmp; 120 121 if(Settings.getStorePasswords()) 122 { 123 searchValue[3] = ptmp; 124 } 125 else 126 { 127 searchValue[3] = ""; 128 } 129 130 searchValue[4] = potmpString; 133 134 searchValue[5] = useLocalString; 135 136 searchValue[6] = LastConnections.SENTINEL; 137 138 updateFileMenu(searchValue); 141 142 return true; 143 } 144 145 } 147 else if(protocol.equals("SMB")) 148 { 149 SmbConnection con = null; 150 151 try 152 { 153 con = new SmbConnection(htmp, dtmp, utmp, ptmp, 154 ((ConnectionListener) JFtp.remoteDir)); 155 156 if(useLocal) 158 { 159 JFtp.statusP.jftp.addLocalConnection(htmp, con); 160 JFtp.localDir.fresh(); 161 } 162 else 163 { 164 JFtp.statusP.jftp.addConnection(htmp, con); 165 JFtp.remoteDir.fresh(); 166 } 167 168 searchValue[0] = "SMB"; 175 searchValue[1] = htmp; 176 searchValue[2] = utmp; 177 178 if(Settings.getStorePasswords()) 179 { 180 searchValue[3] = ptmp; 181 } 182 else 183 { 184 searchValue[3] = ""; 185 } 186 187 searchValue[4] = dtmp; 188 searchValue[5] = useLocalString; 189 searchValue[6] = LastConnections.SENTINEL; 190 191 updateFileMenu(searchValue); 194 195 return true; 196 } 197 catch(Exception ex) 198 { 199 Log.debug("Could not create SMBConnection, does this distribution come with jcifs?"); 200 } 201 } 202 203 else 205 { 206 NfsConnection con; 207 208 boolean status = true; 210 211 con = new NfsConnection(htmp); 213 214 if(!utmp.equals("<anonymous>")) 218 { 219 status = ((NfsConnection) con).login(utmp, ptmp); 220 } 221 222 if(useLocal) 223 { 224 con.setLocalPath("/"); 225 JFtp.statusP.jftp.addLocalConnection(htmp, con); 226 } 227 else 228 { 229 JFtp.statusP.jftp.addConnection(htmp, con); 230 } 231 232 con.chdir(htmp); 233 234 searchValue[0] = "NFS"; 238 searchValue[1] = htmp; 239 searchValue[2] = utmp; 240 241 if(Settings.getStorePasswords()) 242 { 243 searchValue[3] = ptmp; 244 } 245 else 246 { 247 searchValue[3] = ""; 248 } 249 250 searchValue[4] = useLocalString; 251 searchValue[5] = LastConnections.SENTINEL; 252 253 260 updateFileMenu(searchValue); 261 262 return status; 263 } 264 265 279 280 return true; 282 } 283 284 public static int startFtpCon(String htmp, String utmp, String ptmp, 285 int potmp, String dtmp, boolean useLocal) 286 { 287 return startFtpCon(htmp, utmp, ptmp, potmp, dtmp, useLocal, null); 288 } 289 290 public static int startFtpCon(String htmp, String utmp, String ptmp, 292 int potmp, String dtmp, boolean useLocal, String crlf) 293 { 294 boolean pasv = Settings.getFtpPasvMode(); 295 boolean threads = Settings.getEnableMultiThreading(); 296 297 String [] searchValue = new String [JFtp.CONNECTION_DATA_LENGTH]; 300 301 318 con = new FtpConnection(htmp, potmp, dtmp, crlf); 320 321 if(useLocal) 325 { 326 JFtp.statusP.jftp.addLocalConnection(htmp, con); 327 } 328 else 329 { 330 JFtp.statusP.jftp.addConnection(htmp, con); 331 } 332 333 int response = con.login(utmp, ptmp); 336 337 if(response == FtpConnection.LOGIN_OK) 339 { 340 342 350 351 Integer potmpInt = new Integer (potmp); 353 354 String potmpString = potmpInt.toString(); 355 String useLocalString = new String ("false"); 356 357 if(useLocal) 358 { 359 useLocalString = "true"; 360 } 361 362 368 searchValue[0] = "FTP"; 369 searchValue[1] = htmp; 370 searchValue[2] = utmp; 371 372 if(Settings.getStorePasswords()) 373 { 374 searchValue[3] = ptmp; 375 } 376 else 377 { 378 searchValue[3] = ""; 379 } 380 381 searchValue[4] = potmpString; 382 searchValue[5] = dtmp; 383 searchValue[6] = useLocalString; 384 385 searchValue[7] = LastConnections.SENTINEL; 386 updateFileMenu(searchValue); 387 } 388 389 else 391 { 392 if(useLocal) 393 { 394 JFtp.statusP.jftp.closeCurrentLocalTab(); 395 } 396 else 397 { 398 JFtp.statusP.jftp.closeCurrentTab(); 399 } 400 } 401 402 return response; } 404 405 private static void updateFileMenu(String [] searchValue) 407 { 408 int position; 409 410 position = LastConnections.findString(searchValue, JFtp.CAPACITY); 411 412 String [][] newVals = new String [JFtp.CAPACITY][JFtp.CONNECTION_DATA_LENGTH]; 414 415 if(position >= 0) 416 { 417 newVals = LastConnections.moveToFront(position, JFtp.CAPACITY); 421 } 422 else 423 { 424 newVals = LastConnections.prepend(searchValue, JFtp.CAPACITY, true); 426 } 427 } 428 429 } 431 432 433 | Popular Tags |