1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
public void get(String remotePath,String localPath) throws Exception {
String fileName=remoteFileName(remotePath);
remotePath=remoteAbsolutePath(remotePath);
localPath=localAbsolutePath(localPath);
if(isLocalDirectory(localPath)) localPath+=File.separator+fileName;
if(!existsRemotely(remotePath)) throw new Exception(remotePath+": No such file or directory");
else if(isRemoteDirectory(remotePath)) _getDirectory(remotePath,localPath);
else _get(remotePath,localPath);
}
abstract void _get(String remotePath,String localPath) throws Exception;
void _getDirectory(final String remotePath,final String localPath) throws Exception {
String newRemotePath,newLocalPath;
int i;
if(!isLocalDirectory(localPath)) _lmkdir(localPath);
final String[] list=_list(remotePath);
for(i=0;i<list.length;i++) if(!(list[i].equals(".")||list[i].equals(".."))) {
newRemotePath=remotePath+"/"+list[i];
newLocalPath=localPath+File.separator+list[i];
if(isRemoteDirectory(newRemotePath)) _getDirectory(newRemotePath,newLocalPath);
else _get(newRemotePath,newLocalPath);
}
} |