Return-Path: Delivered-To: apmail-jakarta-ant-dev-archive@jakarta.apache.org Received: (qmail 34736 invoked by uid 500); 30 May 2001 05:14:02 -0000 Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk Reply-To: ant-dev@jakarta.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 34692 invoked from network); 30 May 2001 05:13:57 -0000 Message-ID: <004901c0e8c7$16fba3a0$0201a8c0@c325042a> From: "Steve Loughran" To: "ant-dev" Subject: [PATCH] ftp : skipFailedTransfers and IgnoreNoncriticalErrors Date: Tue, 29 May 2001 22:12:13 -0700 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0046_01C0E88C.69FC6CF0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N This is a multi-part message in MIME format. ------=_NextPart_000_0046_01C0E88C.69FC6CF0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit There are two things being addressed in this patch, which jedit makes look slightly bigger than usual due to its stripping off of the odd trailing space. 1. support for wu-ftp : the ignoreCriticalErrors flag hints that the system should ignore non-fatal errors, such as any unexpected responses from the MKDIR command. 2. the ability to skip file transfers that dont work and keep going. This is to deal with big bulk deployment tasks, where for any reason it may not be possible to write to a file at the far end. When the update is particularly time consuming, printing out the problem and continuing is preferable to an immediate halt; then whoever reads the log the next morning can deal with the problem -Steve ------=_NextPart_000_0046_01C0E88C.69FC6CF0 Content-Type: text/plain; name="patch-ftp.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="patch-ftp.txt" cvs diff -u Ftp.java (in directory = D:\Java\Apps\jakarta-ant\src\main\org\apache\tools\ant\taskdefs\optional\= net) Index: FTP.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: = /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/option= al/net/FTP.java,v retrieving revision 1.5 diff -u -r1.5 FTP.java --- FTP.java 2001/01/11 11:53:52 1.5 +++ FTP.java 2001/05/30 04:57:15 @@ -79,9 +79,9 @@ { protected final static int SEND_FILES =3D 0; protected final static int GET_FILES =3D 1; - protected final static int DEL_FILES =3D 2; =20 + protected final static int DEL_FILES =3D 2; protected final static int LIST_FILES =3D 3; - =20 + private String remotedir; private String server; private String userid; @@ -97,6 +97,9 @@ private int transferred =3D 0; private String remoteFileSep =3D "/"; private int port =3D 21; + private boolean skipFailedTransfers=3Dfalse; + private int skipped=3D0; + private boolean ignoreNoncriticalErrors=3Dfalse; =20 protected final static String[] ACTION_STRS =3D { "sending", @@ -110,11 +113,11 @@ "retrieved", "deleted", "listed" - }; =20 - =20 + }; + protected class FTPDirectoryScanner extends DirectoryScanner { protected FTPClient ftp =3D null; - =20 + public FTPDirectoryScanner(FTPClient ftp) { super(); this.ftp =3D ftp; @@ -197,7 +200,7 @@ throw new BuildException("Error while communicating = with FTP server: ", e); } } - } =20 + } =20 /** * Sets the remote directory where files will be placed. This may @@ -336,15 +339,30 @@ throw new BuildException("action " + action + " is not = supported"); } } - =20 + /** * The output file for the "list" action. This attribute is = ignored for * any other actions. */ public void setListing(File listing) throws BuildException { this.listing =3D listing; - } =20 - =20 + } + + + /** + * set the failed transfer flag + */ + public void setSkipFailedTransfers(boolean skipFailedTransfers) { + this.skipFailedTransfers=3DskipFailedTransfers; + } + + /** + * set the flag to skip errors on dir creation (and maybe later = other + * server specific errors) + */ + public void setIgnoreNoncriticalErrors(boolean = ignoreNoncriticalErrors) { + this.ignoreNoncriticalErrors=3DignoreNoncriticalErrors; + } =20 /** * Checks to see that all required parameters are set. @@ -363,7 +381,7 @@ { throw new BuildException("password attribute must be = set!"); } - =20 + if ((action =3D=3D LIST_FILES) && (listing =3D=3D null)) { throw new BuildException("listing attribute must be set for = list action!"); @@ -385,8 +403,8 @@ ds =3D new FTPDirectoryScanner(ftp); fs.setupDirectoryScanner(ds, project); ds.scan(); - } =20 - =20 + } + String[] dsfiles =3D ds.getIncludedFiles(); String dir =3D null; if ((ds.getBasedir() =3D=3D null) && ((action =3D=3D = SEND_FILES) || (action =3D=3D GET_FILES))) { @@ -451,7 +469,8 @@ throws IOException, BuildException { transferred =3D 0; - =20 + skipped=3D0; + if (filesets.size() =3D=3D 0) { throw new BuildException("at least one fileset must be = specified."); @@ -470,6 +489,9 @@ } =20 log(transferred + " files " + COMPLETED_ACTION_STRS[action]); + if(skipped!=3D0) { + log(skipped + " files were not successfully "+ = COMPLETED_ACTION_STRS[action]); + } } =20 /** @@ -515,8 +537,10 @@ // Both codes 550 and 553 can be produced by FTP = Servers // to indicate that an attempt to create a directory = has // failed because the directory already exists. - if (!FTPReply.isPositiveCompletion(ftp.getReplyCode()) = && - (ftp.getReplyCode() !=3D 550) && = (ftp.getReplyCode() !=3D 553)) + int result=3Dftp.getReplyCode(); + if (!FTPReply.isPositiveCompletion(result) && + (result !=3D 550) && (result!=3D 553) && + !ignoreNoncriticalErrors) { throw new BuildException( "could not create = directory: " + @@ -535,7 +559,7 @@ throws IOException, BuildException { log("checking date for " + remoteFile, Project.MSG_VERBOSE); - =20 + FTPFile[] files =3D ftp.listFiles(remoteFile); if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) { @@ -583,27 +607,35 @@ { log("transferring " + file.getAbsolutePath()); } - =20 + instream =3D new BufferedInputStream(new = FileInputStream(file)); - =20 + createParents(ftp, filename); - =20 + ftp.storeFile(resolveFile(filename), instream); - =20 - if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) + boolean = success=3DFTPReply.isPositiveCompletion(ftp.getReplyCode()); + if (!success) { - throw new BuildException( - "could not transfer file: " + - ftp.getReplyString()); - } - =20 - log("File " + file.getAbsolutePath() + " copied to " + = server, - Project.MSG_VERBOSE); + String s=3D"could not put file: " + = ftp.getReplyString(); + if(skipFailedTransfers=3D=3Dtrue) { + log(s,Project.MSG_WARN); + skipped++; + } + else { + throw new BuildException(s); + } =20 - transferred++; + } + else { + + log("File " + file.getAbsolutePath() + + " copied to " + server, + Project.MSG_VERBOSE); + transferred++; + } } finally - { =20 + { if (instream !=3D null) { try @@ -628,18 +660,25 @@ } =20 if (!ftp.deleteFile(resolveFile(filename))) { - throw new BuildException("could not delete file: " + = ftp.getReplyString()); + String s=3D"could not delete file: " + = ftp.getReplyString(); + if(skipFailedTransfers=3D=3Dtrue) { + log(s,Project.MSG_WARN); + skipped++; + } + else { + throw new BuildException(s); + } } - - log("File " + filename + " deleted from " + server, = Project.MSG_VERBOSE);=20 - - transferred++; + else { + log("File " + filename + " deleted from " + server, = Project.MSG_VERBOSE); + transferred++; + } } =20 /** * Retrieve a single file to the remote host. * filename may contain a relative path specification. - * The file will then be retreived using the entire relative path = spec -=20 + * The file will then be retreived using the entire relative path = spec - * no attempt is made to change directories. It is anticipated = that this may * eventually cause problems with some FTP servers, but it = simplifies * the coding. @@ -659,29 +698,35 @@ { log("transferring " + filename + " to " + = file.getAbsolutePath()); } + =20 - =20 File pdir =3D new File(file.getParent()); // stay = 1.1 compatible if (!pdir.exists()) { pdir.mkdirs(); - } =20 + } outstream =3D new BufferedOutputStream(new = FileOutputStream(file)); ftp.retrieveFile(resolveFile(filename), outstream); - =20 + if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) { - throw new BuildException( - "could not transfer file: " + - ftp.getReplyString()); - } - =20 - log("File " + file.getAbsolutePath() + " copied from " + = server, - Project.MSG_VERBOSE); + String s=3D"could not get file: " + = ftp.getReplyString(); + if(skipFailedTransfers=3D=3Dtrue) { + log(s,Project.MSG_WARN); + skipped++; + } + else { + throw new BuildException(s); + } =20 - transferred++; + } + else { + log("File " + file.getAbsolutePath() + " copied from " = + server, + Project.MSG_VERBOSE); + transferred++; + } } finally - { =20 + { if (outstream !=3D null) { try @@ -699,13 +744,13 @@ /** * List information about a single file from the remote host. * filename may contain a relative path specification. - * The file listing will then be retrieved using the entire = relative path spec=20 + * The file listing will then be retrieved using the entire = relative path spec * - no attempt is made to change directories. It is anticipated = that this may * eventually cause problems with some FTP servers, but it = simplifies * the coding. */ protected void listFile(FTPClient ftp, BufferedWriter bw, String = filename) - throws IOException, BuildException=20 + throws IOException, BuildException { if (verbose) { log("listing " + filename); @@ -725,7 +770,7 @@ throws BuildException { checkConfiguration(); - =20 + FTPClient ftp =3D null; =20 try @@ -733,7 +778,7 @@ log("Opening FTP connection to " + server, = Project.MSG_VERBOSE); =20 ftp =3D new FTPClient(); - =20 + ftp.connect(server, port); if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) { @@ -749,7 +794,7 @@ } =20 log("login succeeded", Project.MSG_VERBOSE); - =20 + if (binary) { = ftp.setFileType(com.oroinc.net.ftp.FTP.IMAGE_FILE_TYPE); @@ -760,7 +805,7 @@ ftp.getReplyString()); } } - =20 + if (passive) { log("entering passive mode", Project.MSG_VERBOSE); ------=_NextPart_000_0046_01C0E88C.69FC6CF0 Content-Type: text/plain; name="patch-ftp-man.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="patch-ftp-man.txt" cvs diff -u ftp.html (in directory = D:\Java\Apps\jakarta-ant\docs\manual\OptionalTasks) Index: ftp.html =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: = /home/cvspublic/jakarta-ant/docs/manual/OptionalTasks/ftp.html,v retrieving revision 1.2 diff -u -r1.2 ftp.html --- ftp.html 2001/02/13 12:31:55 1.2 +++ ftp.html 2001/05/30 05:10:02 @@ -106,6 +106,20 @@ Required for the "list" action, ignored = otherwise. No + + ignoreNoncriticalErrors + flag which permits the task to ignore some = non-fatal error + codes sent by some servers during directory creation: wu-ftp in = particular. + Default: false + No + + + skipFailedTransfers + flag which enables unsuccessful file put, delete + and get operations to be skipped with a warning and the + remainder of the files still transferred. Default: false + No + =20

Sending Files

The easiest way to describe how to send files is with a couple of = examples:

------=_NextPart_000_0046_01C0E88C.69FC6CF0--