1 | |
package org.apache.maven.wagon.providers.ftp; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.io.File; |
23 | |
import java.io.FileInputStream; |
24 | |
import java.io.IOException; |
25 | |
import java.io.InputStream; |
26 | |
import java.io.OutputStream; |
27 | |
import java.util.ArrayList; |
28 | |
import java.util.Calendar; |
29 | |
import java.util.List; |
30 | |
|
31 | |
import org.apache.commons.net.ProtocolCommandEvent; |
32 | |
import org.apache.commons.net.ProtocolCommandListener; |
33 | |
import org.apache.commons.net.ftp.FTP; |
34 | |
import org.apache.commons.net.ftp.FTPClient; |
35 | |
import org.apache.commons.net.ftp.FTPFile; |
36 | |
import org.apache.commons.net.ftp.FTPReply; |
37 | |
import org.apache.maven.wagon.ConnectionException; |
38 | |
import org.apache.maven.wagon.InputData; |
39 | |
import org.apache.maven.wagon.OutputData; |
40 | |
import org.apache.maven.wagon.PathUtils; |
41 | |
import org.apache.maven.wagon.ResourceDoesNotExistException; |
42 | |
import org.apache.maven.wagon.StreamWagon; |
43 | |
import org.apache.maven.wagon.TransferFailedException; |
44 | |
import org.apache.maven.wagon.WagonConstants; |
45 | |
import org.apache.maven.wagon.authentication.AuthenticationException; |
46 | |
import org.apache.maven.wagon.authentication.AuthenticationInfo; |
47 | |
import org.apache.maven.wagon.authorization.AuthorizationException; |
48 | |
import org.apache.maven.wagon.repository.RepositoryPermissions; |
49 | |
import org.apache.maven.wagon.resource.Resource; |
50 | |
import org.codehaus.plexus.util.IOUtil; |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | 36 | public class FtpWagon |
62 | |
extends StreamWagon |
63 | |
{ |
64 | |
private FTPClient ftp; |
65 | |
|
66 | |
|
67 | 36 | private boolean passiveMode = true; |
68 | |
|
69 | |
public boolean isPassiveMode() |
70 | |
{ |
71 | 34 | return passiveMode; |
72 | |
} |
73 | |
|
74 | |
public void setPassiveMode( boolean passiveMode ) |
75 | |
{ |
76 | 0 | this.passiveMode = passiveMode; |
77 | 0 | } |
78 | |
|
79 | |
protected void openConnectionInternal() |
80 | |
throws ConnectionException, AuthenticationException |
81 | |
{ |
82 | 36 | AuthenticationInfo authInfo = getAuthenticationInfo(); |
83 | |
|
84 | 36 | if ( authInfo == null ) |
85 | |
{ |
86 | 0 | throw new IllegalArgumentException( "Authentication Credentials cannot be null for FTP protocol" ); |
87 | |
} |
88 | |
|
89 | 36 | if ( authInfo.getUserName() == null ) |
90 | |
{ |
91 | 1 | authInfo.setUserName( System.getProperty( "user.name" ) ); |
92 | |
} |
93 | |
|
94 | 36 | String username = authInfo.getUserName(); |
95 | |
|
96 | 36 | String password = authInfo.getPassword(); |
97 | |
|
98 | 36 | if ( username == null ) |
99 | |
{ |
100 | 0 | throw new AuthenticationException( "Username not specified for repository " + getRepository().getId() ); |
101 | |
} |
102 | 36 | if ( password == null ) |
103 | |
{ |
104 | 1 | throw new AuthenticationException( "Password not specified for repository " + getRepository().getId() ); |
105 | |
} |
106 | |
|
107 | 35 | String host = getRepository().getHost(); |
108 | |
|
109 | 35 | ftp = new FTPClient(); |
110 | 35 | ftp.setDefaultTimeout( getTimeout() ); |
111 | 35 | ftp.setDataTimeout( getTimeout() ); |
112 | |
|
113 | 35 | ftp.addProtocolCommandListener( new PrintCommandListener( this ) ); |
114 | |
|
115 | |
try |
116 | |
{ |
117 | 35 | if ( getRepository().getPort() != WagonConstants.UNKNOWN_PORT ) |
118 | |
{ |
119 | 35 | ftp.connect( host, getRepository().getPort() ); |
120 | |
} |
121 | |
else |
122 | |
{ |
123 | 0 | ftp.connect( host ); |
124 | |
} |
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | 34 | int reply = ftp.getReplyCode(); |
130 | |
|
131 | 34 | if ( !FTPReply.isPositiveCompletion( reply ) ) |
132 | |
{ |
133 | 0 | ftp.disconnect(); |
134 | |
|
135 | 0 | throw new AuthenticationException( "FTP server refused connection." ); |
136 | |
} |
137 | |
} |
138 | 1 | catch ( IOException e ) |
139 | |
{ |
140 | 1 | if ( ftp.isConnected() ) |
141 | |
{ |
142 | |
try |
143 | |
{ |
144 | 0 | fireSessionError( e ); |
145 | |
|
146 | 0 | ftp.disconnect(); |
147 | |
} |
148 | 0 | catch ( IOException f ) |
149 | |
{ |
150 | |
|
151 | 0 | } |
152 | |
} |
153 | |
|
154 | 1 | throw new AuthenticationException( "Could not connect to server.", e ); |
155 | 34 | } |
156 | |
|
157 | |
try |
158 | |
{ |
159 | 34 | if ( !ftp.login( username, password ) ) |
160 | |
{ |
161 | 0 | throw new AuthenticationException( "Cannot login to remote system" ); |
162 | |
} |
163 | |
|
164 | 34 | fireSessionDebug( "Remote system is " + ftp.getSystemName() ); |
165 | |
|
166 | |
|
167 | 34 | ftp.setFileType( FTP.BINARY_FILE_TYPE ); |
168 | 34 | ftp.setListHiddenFiles( true ); |
169 | |
|
170 | |
|
171 | |
|
172 | 34 | if ( isPassiveMode() ) |
173 | |
{ |
174 | 34 | ftp.enterLocalPassiveMode(); |
175 | |
} |
176 | |
} |
177 | 0 | catch ( IOException e ) |
178 | |
{ |
179 | 0 | throw new ConnectionException( "Cannot login to remote system", e ); |
180 | 34 | } |
181 | 34 | } |
182 | |
|
183 | |
protected void firePutCompleted( Resource resource, File file ) |
184 | |
{ |
185 | |
try |
186 | |
{ |
187 | |
|
188 | 14 | ftp.completePendingCommand(); |
189 | |
|
190 | 14 | RepositoryPermissions permissions = repository.getPermissions(); |
191 | |
|
192 | 14 | if ( permissions != null && permissions.getGroup() != null ) |
193 | |
{ |
194 | |
|
195 | 0 | ftp.sendSiteCommand( "CHGRP " + permissions.getGroup() + " " + resource.getName() ); |
196 | |
} |
197 | |
|
198 | 14 | if ( permissions != null && permissions.getFileMode() != null ) |
199 | |
{ |
200 | |
|
201 | 0 | ftp.sendSiteCommand( "CHMOD " + permissions.getFileMode() + " " + resource.getName() ); |
202 | |
} |
203 | |
} |
204 | 0 | catch ( IOException e ) |
205 | |
{ |
206 | |
|
207 | |
|
208 | |
|
209 | 14 | } |
210 | |
|
211 | 14 | super.firePutCompleted( resource, file ); |
212 | 14 | } |
213 | |
|
214 | |
protected void fireGetCompleted( Resource resource, File localFile ) |
215 | |
{ |
216 | |
try |
217 | |
{ |
218 | 22 | ftp.completePendingCommand(); |
219 | |
} |
220 | 0 | catch ( IOException e ) |
221 | |
{ |
222 | |
|
223 | |
|
224 | |
|
225 | |
|
226 | 22 | } |
227 | 22 | super.fireGetCompleted( resource, localFile ); |
228 | 22 | } |
229 | |
|
230 | |
public void closeConnection() |
231 | |
throws ConnectionException |
232 | |
{ |
233 | 34 | if ( ftp != null && ftp.isConnected() ) |
234 | |
{ |
235 | |
try |
236 | |
{ |
237 | |
|
238 | 34 | ftp.disconnect(); |
239 | |
} |
240 | 0 | catch ( IOException e ) |
241 | |
{ |
242 | 0 | throw new ConnectionException( "Failed to close connection to FTP repository", e ); |
243 | 34 | } |
244 | |
} |
245 | 34 | } |
246 | |
|
247 | |
public void fillOutputData( OutputData outputData ) |
248 | |
throws TransferFailedException |
249 | |
{ |
250 | |
OutputStream os; |
251 | |
|
252 | 14 | Resource resource = outputData.getResource(); |
253 | |
|
254 | 14 | RepositoryPermissions permissions = repository.getPermissions(); |
255 | |
|
256 | |
try |
257 | |
{ |
258 | 14 | if ( !ftp.changeWorkingDirectory( getRepository().getBasedir() ) ) |
259 | |
{ |
260 | 0 | throw new TransferFailedException( |
261 | |
"Required directory: '" + getRepository().getBasedir() + "' " + "is missing" ); |
262 | |
} |
263 | |
|
264 | 14 | String[] dirs = PathUtils.dirnames( resource.getName() ); |
265 | |
|
266 | 19 | for ( int i = 0; i < dirs.length; i++ ) |
267 | |
{ |
268 | 5 | boolean dirChanged = ftp.changeWorkingDirectory( dirs[i] ); |
269 | |
|
270 | 5 | if ( !dirChanged ) |
271 | |
{ |
272 | |
|
273 | 1 | boolean success = ftp.makeDirectory( dirs[i] ); |
274 | |
|
275 | 1 | if ( success ) |
276 | |
{ |
277 | 1 | if ( permissions != null && permissions.getGroup() != null ) |
278 | |
{ |
279 | |
|
280 | 0 | ftp.sendSiteCommand( "CHGRP " + permissions.getGroup() + " " + dirs[i] ); |
281 | |
} |
282 | |
|
283 | 1 | if ( permissions != null && permissions.getDirectoryMode() != null ) |
284 | |
{ |
285 | |
|
286 | 0 | ftp.sendSiteCommand( "CHMOD " + permissions.getDirectoryMode() + " " + dirs[i] ); |
287 | |
} |
288 | |
|
289 | 1 | dirChanged = ftp.changeWorkingDirectory( dirs[i] ); |
290 | |
} |
291 | |
} |
292 | |
|
293 | 5 | if ( !dirChanged ) |
294 | |
{ |
295 | 0 | throw new TransferFailedException( "Unable to create directory " + dirs[i] ); |
296 | |
} |
297 | |
} |
298 | |
|
299 | |
|
300 | |
|
301 | 14 | if ( !ftp.changeWorkingDirectory( getRepository().getBasedir() ) ) |
302 | |
{ |
303 | 0 | throw new TransferFailedException( "Unable to return to the base directory" ); |
304 | |
} |
305 | |
|
306 | 14 | os = ftp.storeFileStream( resource.getName() ); |
307 | |
|
308 | 14 | if ( os == null ) |
309 | |
{ |
310 | 0 | String msg = "Cannot transfer resource: '" + resource |
311 | |
+ "'. Output stream is null. FTP Server response: " + ftp.getReplyString(); |
312 | |
|
313 | 0 | throw new TransferFailedException( msg ); |
314 | |
|
315 | |
} |
316 | |
|
317 | 14 | fireTransferDebug( "resource = " + resource ); |
318 | |
|
319 | |
} |
320 | 0 | catch ( IOException e ) |
321 | |
{ |
322 | 0 | throw new TransferFailedException( "Error transferring over FTP", e ); |
323 | 14 | } |
324 | |
|
325 | 14 | outputData.setOutputStream( os ); |
326 | |
|
327 | 14 | } |
328 | |
|
329 | |
|
330 | |
|
331 | |
|
332 | |
|
333 | |
public void fillInputData( InputData inputData ) |
334 | |
throws TransferFailedException, ResourceDoesNotExistException |
335 | |
{ |
336 | |
InputStream is; |
337 | |
|
338 | 30 | Resource resource = inputData.getResource(); |
339 | |
|
340 | |
try |
341 | |
{ |
342 | 30 | ftpChangeDirectory( resource ); |
343 | |
|
344 | 30 | String filename = PathUtils.filename( resource.getName() ); |
345 | 30 | FTPFile[] ftpFiles = ftp.listFiles( filename ); |
346 | |
|
347 | 30 | if ( ftpFiles == null || ftpFiles.length <= 0 ) |
348 | |
{ |
349 | 4 | throw new ResourceDoesNotExistException( "Could not find file: '" + resource + "'" ); |
350 | |
} |
351 | |
|
352 | 26 | long contentLength = ftpFiles[0].getSize(); |
353 | |
|
354 | |
|
355 | |
|
356 | |
|
357 | 26 | Calendar timestamp = ftpFiles[0].getTimestamp(); |
358 | 26 | long lastModified = timestamp != null ? timestamp.getTimeInMillis() : 0; |
359 | |
|
360 | 26 | resource.setContentLength( contentLength ); |
361 | |
|
362 | 26 | resource.setLastModified( lastModified ); |
363 | |
|
364 | 26 | is = ftp.retrieveFileStream( filename ); |
365 | |
} |
366 | 0 | catch ( IOException e ) |
367 | |
{ |
368 | 0 | throw new TransferFailedException( "Error transferring file via FTP", e ); |
369 | 26 | } |
370 | |
|
371 | 26 | inputData.setInputStream( is ); |
372 | 26 | } |
373 | |
|
374 | |
private void ftpChangeDirectory( Resource resource ) |
375 | |
throws IOException, TransferFailedException, ResourceDoesNotExistException |
376 | |
{ |
377 | 35 | if ( !ftp.changeWorkingDirectory( getRepository().getBasedir() ) ) |
378 | |
{ |
379 | 0 | throw new ResourceDoesNotExistException( |
380 | |
"Required directory: '" + getRepository().getBasedir() + "' " + "is missing" ); |
381 | |
} |
382 | |
|
383 | 35 | String[] dirs = PathUtils.dirnames( resource.getName() ); |
384 | |
|
385 | 81 | for ( int i = 0; i < dirs.length; i++ ) |
386 | |
{ |
387 | 47 | boolean dirChanged = ftp.changeWorkingDirectory( dirs[i] ); |
388 | |
|
389 | 47 | if ( !dirChanged ) |
390 | |
{ |
391 | 1 | String msg = "Resource " + resource + " not found. Directory " + dirs[i] + " does not exist"; |
392 | |
|
393 | 1 | throw new ResourceDoesNotExistException( msg ); |
394 | |
} |
395 | |
} |
396 | 34 | } |
397 | |
|
398 | 36 | public class PrintCommandListener |
399 | |
implements ProtocolCommandListener |
400 | |
{ |
401 | |
private FtpWagon wagon; |
402 | |
|
403 | |
public PrintCommandListener( FtpWagon wagon ) |
404 | 35 | { |
405 | 35 | this.wagon = wagon; |
406 | 35 | } |
407 | |
|
408 | |
public void protocolCommandSent( ProtocolCommandEvent event ) |
409 | |
{ |
410 | 525 | wagon.fireSessionDebug( "Command sent: " + event.getMessage() ); |
411 | |
|
412 | 525 | } |
413 | |
|
414 | |
public void protocolReplyReceived( ProtocolCommandEvent event ) |
415 | |
{ |
416 | 646 | wagon.fireSessionDebug( "Reply received: " + event.getMessage() ); |
417 | 646 | } |
418 | |
} |
419 | |
|
420 | |
protected void fireSessionDebug( String msg ) |
421 | |
{ |
422 | 1205 | super.fireSessionDebug( msg ); |
423 | 1205 | } |
424 | |
|
425 | |
public List getFileList( String destinationDirectory ) |
426 | |
throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException |
427 | |
{ |
428 | 3 | Resource resource = new Resource( destinationDirectory ); |
429 | |
|
430 | |
try |
431 | |
{ |
432 | 3 | ftpChangeDirectory( resource ); |
433 | |
|
434 | 3 | String filename = PathUtils.filename( resource.getName() ); |
435 | 3 | FTPFile[] ftpFiles = ftp.listFiles( filename ); |
436 | |
|
437 | 3 | if ( ftpFiles == null || ftpFiles.length <= 0 ) |
438 | |
{ |
439 | 1 | throw new ResourceDoesNotExistException( "Could not find file: '" + resource + "'" ); |
440 | |
} |
441 | |
|
442 | 2 | List ret = new ArrayList(); |
443 | 8 | for( int i=0; i < ftpFiles.length; i++ ) |
444 | |
{ |
445 | 6 | String name = ftpFiles[i].getName(); |
446 | |
|
447 | 6 | if ( ftpFiles[i].isDirectory() && !name.endsWith( "/" ) ) |
448 | |
{ |
449 | 1 | name += "/"; |
450 | |
} |
451 | |
|
452 | 6 | ret.add( name ); |
453 | |
} |
454 | |
|
455 | 2 | return ret; |
456 | |
} |
457 | 0 | catch ( IOException e ) |
458 | |
{ |
459 | 0 | throw new TransferFailedException( "Error transferring file via FTP", e ); |
460 | |
} |
461 | |
} |
462 | |
|
463 | |
public boolean resourceExists( String resourceName ) |
464 | |
throws TransferFailedException, AuthorizationException |
465 | |
{ |
466 | 2 | Resource resource = new Resource( resourceName ); |
467 | |
|
468 | |
try |
469 | |
{ |
470 | 2 | ftpChangeDirectory( resource ); |
471 | |
|
472 | 1 | String filename = PathUtils.filename( resource.getName() ); |
473 | 1 | int status = ftp.stat( filename ); |
474 | |
|
475 | 1 | return ( ( status == FTPReply.FILE_STATUS ) || ( status == FTPReply.FILE_STATUS_OK ) |
476 | |
|| ( status == FTPReply.SYSTEM_STATUS ) ); |
477 | |
} |
478 | 0 | catch ( IOException e ) |
479 | |
{ |
480 | 0 | throw new TransferFailedException( "Error transferring file via FTP", e ); |
481 | |
} |
482 | 1 | catch ( ResourceDoesNotExistException e ) |
483 | |
{ |
484 | 1 | return false; |
485 | |
} |
486 | |
} |
487 | |
|
488 | |
public boolean supportsDirectoryCopy() |
489 | |
{ |
490 | 4 | return true; |
491 | |
} |
492 | |
|
493 | |
public void putDirectory( File sourceDirectory, String destinationDirectory ) |
494 | |
throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException |
495 | |
{ |
496 | |
|
497 | |
|
498 | |
try |
499 | |
{ |
500 | 4 | if ( !ftp.changeWorkingDirectory( getRepository().getBasedir() ) ) |
501 | |
{ |
502 | 0 | throw new TransferFailedException( "Required directory: '" + getRepository().getBasedir() + "' " |
503 | |
+ "is missing" ); |
504 | |
} |
505 | |
} |
506 | 0 | catch ( IOException e ) |
507 | |
{ |
508 | 0 | throw new TransferFailedException( "Cannot change to root path " + getRepository().getBasedir() ); |
509 | 4 | } |
510 | |
|
511 | 4 | fireTransferDebug( "Recursively uploading directory " + sourceDirectory.getAbsolutePath() + " as " |
512 | |
+ destinationDirectory ); |
513 | 4 | ftpRecursivePut( sourceDirectory, destinationDirectory ); |
514 | 4 | } |
515 | |
|
516 | |
private void ftpRecursivePut( File sourceFile, String fileName ) throws TransferFailedException |
517 | |
{ |
518 | 40 | final RepositoryPermissions permissions = repository.getPermissions(); |
519 | |
|
520 | 40 | fireTransferDebug( "processing = " + sourceFile.getAbsolutePath() + " as " + fileName ); |
521 | |
|
522 | 40 | if ( sourceFile.isDirectory() ) |
523 | |
{ |
524 | 22 | if ( !fileName.equals( "." ) ) |
525 | |
{ |
526 | |
try |
527 | |
{ |
528 | |
|
529 | 21 | if ( !ftp.changeWorkingDirectory( fileName ) ) |
530 | |
{ |
531 | |
|
532 | 21 | if ( ftp.makeDirectory( fileName ) ) |
533 | |
{ |
534 | 21 | if ( permissions != null ) |
535 | |
{ |
536 | |
|
537 | |
|
538 | 21 | String group = permissions.getGroup(); |
539 | 21 | if ( group != null ) |
540 | |
{ |
541 | |
try |
542 | |
{ |
543 | 0 | ftp.sendSiteCommand( "CHGRP " + permissions.getGroup() ); |
544 | |
} |
545 | 0 | catch ( IOException e ) |
546 | |
{ |
547 | 0 | } |
548 | |
} |
549 | 21 | String mode = permissions.getDirectoryMode(); |
550 | 21 | if ( mode != null ) |
551 | |
{ |
552 | |
try |
553 | |
{ |
554 | 0 | ftp.sendSiteCommand( "CHMOD " + permissions.getDirectoryMode() ); |
555 | |
} |
556 | 0 | catch ( IOException e ) |
557 | |
{ |
558 | 0 | } |
559 | |
} |
560 | |
} |
561 | |
|
562 | 21 | if ( !ftp.changeWorkingDirectory( fileName ) ) |
563 | |
{ |
564 | 0 | throw new TransferFailedException( "Unable to change cwd on ftp server to " + fileName |
565 | |
+ " when processing " + sourceFile.getAbsolutePath() ); |
566 | |
} |
567 | |
} |
568 | |
else |
569 | |
{ |
570 | 0 | throw new TransferFailedException( "Unable to create directory " + fileName |
571 | |
+ " when processing " + sourceFile.getAbsolutePath() ); |
572 | |
} |
573 | |
} |
574 | |
} |
575 | 0 | catch ( IOException e ) |
576 | |
{ |
577 | 0 | throw new TransferFailedException( "IOException caught while processing path at " |
578 | |
+ sourceFile.getAbsolutePath(), e ); |
579 | 21 | } |
580 | |
} |
581 | |
|
582 | 22 | File[] files = sourceFile.listFiles(); |
583 | 22 | if ( files != null && files.length > 0 ) |
584 | |
{ |
585 | 22 | fireTransferDebug( "listing children of = " + sourceFile.getAbsolutePath() + " found " + files.length ); |
586 | |
|
587 | |
|
588 | 58 | for ( int i = 0; i < files.length; i++ ) |
589 | |
{ |
590 | 36 | if ( files[i].isDirectory() ) |
591 | |
{ |
592 | 18 | ftpRecursivePut( files[i], files[i].getName() ); |
593 | |
} |
594 | |
} |
595 | 58 | for ( int i = 0; i < files.length; i++ ) |
596 | |
{ |
597 | 36 | if ( !files[i].isDirectory() ) |
598 | |
{ |
599 | 18 | ftpRecursivePut( files[i], files[i].getName() ); |
600 | |
} |
601 | |
} |
602 | |
} |
603 | |
|
604 | |
|
605 | |
try |
606 | |
{ |
607 | 22 | ftp.changeToParentDirectory(); |
608 | |
} |
609 | 0 | catch ( IOException e ) |
610 | |
{ |
611 | 0 | throw new TransferFailedException( "IOException caught while attempting to step up to parent directory" |
612 | |
+ " after successfully processing " + sourceFile.getAbsolutePath(), |
613 | |
e ); |
614 | 22 | } |
615 | 22 | } |
616 | |
else |
617 | |
{ |
618 | |
|
619 | |
|
620 | 18 | FileInputStream sourceFileStream = null; |
621 | |
try |
622 | |
{ |
623 | 18 | sourceFileStream = new FileInputStream( sourceFile ); |
624 | |
|
625 | |
|
626 | 18 | if ( ftp.storeFile( fileName, sourceFileStream ) ) |
627 | |
{ |
628 | 18 | if ( permissions != null ) |
629 | |
{ |
630 | |
|
631 | |
|
632 | 18 | String group = permissions.getGroup(); |
633 | 18 | if ( group != null ) |
634 | |
try |
635 | |
{ |
636 | 0 | ftp.sendSiteCommand( "CHGRP " + permissions.getGroup() ); |
637 | |
} |
638 | 0 | catch ( IOException e ) |
639 | |
{ |
640 | 0 | } |
641 | 18 | String mode = permissions.getFileMode(); |
642 | 18 | if ( mode != null ) |
643 | |
try |
644 | |
{ |
645 | 0 | ftp.sendSiteCommand( "CHMOD " + permissions.getDirectoryMode() ); |
646 | |
} |
647 | 0 | catch ( IOException e ) |
648 | |
{ |
649 | 0 | } |
650 | 18 | } |
651 | |
} |
652 | |
else |
653 | |
{ |
654 | 0 | String msg = |
655 | |
"Cannot transfer resource: '" + sourceFile.getAbsolutePath() + "' FTP Server response: " |
656 | |
+ ftp.getReplyString(); |
657 | 0 | throw new TransferFailedException( msg ); |
658 | |
} |
659 | |
} |
660 | 0 | catch ( IOException e ) |
661 | |
{ |
662 | 0 | throw new TransferFailedException( "IOException caught while attempting to upload " |
663 | |
+ sourceFile.getAbsolutePath(), e ); |
664 | |
} |
665 | |
finally |
666 | |
{ |
667 | 18 | IOUtil.close( sourceFileStream ); |
668 | 18 | } |
669 | |
|
670 | |
} |
671 | |
|
672 | 40 | fireTransferDebug( "completed = " + sourceFile.getAbsolutePath() ); |
673 | 40 | } |
674 | |
} |