use of net.schmizz.sshj.sftp.SFTPException in project AmazeFileManager by TeamAmaze.
the class HybridFile method getUsableSpace.
/**
* Gets usable i.e. free space of a device
* @return
*/
public long getUsableSpace() {
long size = 0L;
switch(mode) {
case SMB:
try {
size = (new SmbFile(path).getDiskFreeSpace());
} catch (MalformedURLException e) {
size = 0L;
e.printStackTrace();
} catch (SmbException e) {
size = 0L;
e.printStackTrace();
}
break;
case FILE:
case ROOT:
size = new File(path).getUsableSpace();
break;
case DROPBOX:
case BOX:
case GDRIVE:
case ONEDRIVE:
SpaceAllocation spaceAllocation = dataUtils.getAccount(mode).getAllocation();
size = spaceAllocation.getTotal() - spaceAllocation.getUsed();
break;
case SFTP:
size = SshClientUtils.execute(new SFtpClientTemplate(path) {
@Override
public Long execute(@NonNull SFTPClient client) throws IOException {
try {
Statvfs.Response response = new Statvfs.Response(path, client.getSFTPEngine().request(Statvfs.request(client, SshClientUtils.extractRemotePathFrom(path))).retrieve());
return response.diskFreeSpace();
} catch (SFTPException e) {
Log.e(TAG, "Error querying server", e);
return 0L;
} catch (Buffer.BufferException e) {
Log.e(TAG, "Error parsing reply", e);
return 0L;
}
}
});
break;
case OTG:
// TODO: Get free space from OTG when {@link DocumentFile} API adds support
break;
}
return size;
}
use of net.schmizz.sshj.sftp.SFTPException in project AmazeFileManager by TeamAmaze.
the class HybridFile method getTotal.
/**
* Gets total size of the disk
* @param context
* @return
*/
public long getTotal(Context context) {
long size = 0l;
switch(mode) {
case SMB:
// TODO: Find total storage space of SMB when JCIFS adds support
try {
size = new SmbFile(path).getDiskFreeSpace();
} catch (SmbException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
}
break;
case FILE:
case ROOT:
size = new File(path).getTotalSpace();
break;
case DROPBOX:
case BOX:
case ONEDRIVE:
case GDRIVE:
SpaceAllocation spaceAllocation = dataUtils.getAccount(mode).getAllocation();
size = spaceAllocation.getTotal();
break;
case SFTP:
size = SshClientUtils.execute(new SFtpClientTemplate(path) {
@Override
public Long execute(@NonNull SFTPClient client) throws IOException {
try {
Statvfs.Response response = new Statvfs.Response(path, client.getSFTPEngine().request(Statvfs.request(client, SshClientUtils.extractRemotePathFrom(path))).retrieve());
return response.diskSize();
} catch (SFTPException e) {
Log.e(TAG, "Error querying server", e);
return 0L;
} catch (Buffer.BufferException e) {
Log.e(TAG, "Error parsing reply", e);
return 0L;
}
}
});
break;
case OTG:
// TODO: Find total storage space of OTG when {@link DocumentFile} API adds support
DocumentFile documentFile = OTGUtil.getDocumentFile(path, context, false);
documentFile.length();
break;
}
return size;
}
use of net.schmizz.sshj.sftp.SFTPException in project AmazeFileManager by TeamAmaze.
the class HybridFile method exists.
public boolean exists() {
boolean exists = false;
if (isSftp()) {
exists = SshClientUtils.execute(new SFtpClientTemplate(path) {
@Override
public Boolean execute(SFTPClient client) throws IOException {
try {
return client.stat(SshClientUtils.extractRemotePathFrom(path)) != null;
} catch (SFTPException notFound) {
return false;
}
}
});
} else if (isSmb()) {
try {
SmbFile smbFile = getSmbFile(2000);
exists = smbFile != null && smbFile.exists();
} catch (SmbException e) {
exists = false;
}
} else if (isDropBoxFile()) {
CloudStorage cloudStorageDropbox = dataUtils.getAccount(OpenMode.DROPBOX);
exists = cloudStorageDropbox.exists(CloudUtil.stripPath(OpenMode.DROPBOX, path));
} else if (isBoxFile()) {
CloudStorage cloudStorageBox = dataUtils.getAccount(OpenMode.BOX);
exists = cloudStorageBox.exists(CloudUtil.stripPath(OpenMode.BOX, path));
} else if (isGoogleDriveFile()) {
CloudStorage cloudStorageGoogleDrive = dataUtils.getAccount(OpenMode.GDRIVE);
exists = cloudStorageGoogleDrive.exists(CloudUtil.stripPath(OpenMode.GDRIVE, path));
} else if (isOneDriveFile()) {
CloudStorage cloudStorageOneDrive = dataUtils.getAccount(OpenMode.ONEDRIVE);
exists = cloudStorageOneDrive.exists(CloudUtil.stripPath(OpenMode.ONEDRIVE, path));
} else if (isLocal()) {
exists = new File(path).exists();
} else if (isRoot()) {
try {
return RootHelper.fileExists(path);
} catch (ShellNotRunningException e) {
e.printStackTrace();
return false;
}
}
return exists;
}
Aggregations