Bug 42781 - optional task SCP (sftp=true) fails if remote dir does not exist or does contain "~"
Summary: optional task SCP (sftp=true) fails if remote dir does not exist or does cont...
Status: RESOLVED FIXED
Alias: None
Product: Ant
Classification: Unclassified
Component: Core (show other bugs)
Version: 1.7.0
Hardware: PC Windows XP
: P2 enhancement (vote)
Target Milestone: 1.8.0
Assignee: Ant Notifications List
URL:
Keywords: ErrorMessage, PatchAvailable
Depends on:
Blocks:
 
Reported: 2007-06-29 09:24 UTC by Eduard Wirch
Modified: 2008-07-16 02:33 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eduard Wirch 2007-06-29 09:24:27 UTC
If task scp with sftp enabled is used, and the remote dir name contains "~"
(example: ~/), the task will fail with an "No such file" exception. I spent two
hours searching for the reason. The exception should be more meaningful.

Additionally the scp task will fail if the remote dir does not exist. The remote
dir should be created automatically if it does not exist.

Here is the patch for the changes I made on
org.apache.tools.ant.taskdefs.optional.ssh.ScpToMessageBySftp.java:

148a149
> 			// change dir on remote machine to the upload dir. create it if it does not
exist
149a151,158
> 		        try {
> 		            channel.stat(remotePath);
> 		        } catch (SftpException e) {
> 		            // dir does not exist.
> 		            if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) {
> 		                channel.mkdir(remotePath);
> 		            }
> 		        }
150a160,165
>             } catch (SftpException e) {
>             	throw new JSchException("failed changing remote dir to
'"+remotePath+"': "+e.toString());
>         	}
> 
>         	Directory current = null;
>         	try {
152c167
<                     Directory current = (Directory) i.next();
---
>                     current = (Directory) i.next();
156c171,175
<                 throw new JSchException(e.toString());
---
>             	if (current != null) {
>                 	throw new JSchException(e.toString()+" during sending
directory '"+current.getDirectory().getName()+"'");
>                 } else {
>                 	throw new JSchException(e.toString());
>                 }
Comment 1 Stefan Bodewig 2008-07-16 02:33:04 UTC
subversion revision 677211