/* * Creates a directory using a request from an FTP wrapper */ public String create(FTPTestWrapperAbstract wrapper) { try { FtpWebResponse response = wrapper.getResp(); if (response != null) { if ((int)response.StatusCode >= 300) { return("Error - could not copy file"); } } } catch (WebException e) { if (e.Message.ToString().Equals("The remote server returned an error: (550) File unavailable (e.g., file not found, no access).")) { return("The server sent an error code of 550. The file may already exist or the file was unavailable due to a lack of access."); } return(e.Message.ToString()); } catch (System.UriFormatException e) { return("Poorly formatted URI. Please enter a valid file name"); } return("success"); }
//Main class to change the permissions. Invokes the wrapper's run method //and returns success. If an exception arises, returns an appropriate error message. public String change(FTPTestWrapperAbstract wrapper) { //Note: This uses FluentFTP as the Microsoft library does not enable the use of SITE commands. //When I discussed this with the team, people wanted to use a combination of both libraries than switch //Exclusively to FluentFTP. try { //Open connection and make change wrapper.runFluent(0); return("success"); //Handle Exceptions thrown by FluentFTP } catch (FluentFTP.FtpAuthenticationException) { return("Server Validation Failed\n"); } catch (ArgumentException) { return("The Path was Blank"); } catch (FluentFTP.FtpCommandException e) { if (e.Message.Equals("Command not implemented for that parameter")) { return("504 Error from Server: This Server Has Not Implemented the CHMOD command.\n"); } return(e.Message); }catch (System.Net.Sockets.SocketException) { return("Error when attempting to connect - Socket connection refused."); } catch (WebException e) { if (e.Message.ToString().Equals("The remote server returned an error: (550) File unavailable (e.g., file not found, no access).")) { return("The server sent an error code of 550. The file may not exist or file was unavailable due to a lack of access."); } return(e.Message.ToString()); } catch (System.UriFormatException e) { return("Poorly formatted URI. Please enter a valid path."); }catch (Exception e) { return("Error when trying to send request to host. The server may be offline."); } }