[英]chmod command in data pump directory not working second time using Java code deployed on oracle weblogic server
我正在嘗試使用expdp cmd創建表A_LOCKER的dmp文件,然后將其通過ftp發送回部署了Java代碼的本地計算機。該服務器是oracle weblogic服務器。 該代碼第一次可以正常工作,但是從第二次開始它給出錯誤為:權限被拒絕
dmp文件是在我創建的數據泵目錄Extract中創建的。
現在,我嘗試對dmp文件進行sftp傳輸,為此,我需要為該文件提供sudo權限,因此我在Java代碼中嘗試了以下操作:1)創建會話:
StringBuffer cmd = new StringBuffer();
FileOutputStream fileOutputStream = null;
SshClient ssh = new SshClient();
SessionChannelClient session = null;
SftpClient sftp = null;
HostKeyVerification host = new IgnoreHostKeyVerification();
// Try to connect to the machine that includes the shared folder
// Throw an exception when a connection is failed.
try {
ssh.connect(machine, host);
} catch (IOException e) {
logger.error("Cannot connect to dbserver in machine "
+ machine,e);
throw new EPCShareFileException(
"Cannot connect to dbserver location in machine "
+ machine, e);
}
PasswordAuthenticationClient auth = new PasswordAuthenticationClient();
auth.setUsername(user);
auth.setPassword(password);
// Authenticate user name and password for connection
// Throw an exception if authentication is failed
try {
ssh.authenticate(auth);
} catch (IOException e) {
logger.error("Cannot authenticate user "
+ user + " " + " password " + password);
ssh.disconnect();
throw new EPCShareFileException("Cannot authenticate user "
+ user + " " + " password " + password, e);
}
2)使用偽權限執行chmod命令
cmd.append("/usr/local/bin/sudo /bin/chmod -R 777 ")
.append(location+dbDumpFileName);
try{
session = ssh.openSessionChannel();
session.executeCommand(cmd.toString());
} catch (IOException e){
logger.error("Cannot execute chmod cmd");
}
finally{
try {
session.close();
} catch (IOException e) {
// TODO Auto-generated catch block
logger.info("Cannot close the session:"+e.getMessage());
}
}
3)然后我正在嘗試將dmp文件sftp到本地服務器
try {
sftp = ssh.openSftpClient();
} catch (IOException e) {
logger.error("Cannot open connection to database server");
ssh.disconnect();
throw new EPCShareFileException(
"Cannot open connection to database server");
}
try{
fileOutputStream = new FileOutputStream(dbDumpFileName);
sftp.get(location+dbDumpFileName, fileOutputStream);
}catch (IOException e) {
**throw new EPCShareFileException("Cannot retrive file "
+"Error:"+e.getMessage());**
}finally{
try {
fileOutputStream.close();
sftp.quit();
fileOutputStream = null;
sftp = null;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ssh.disconnect();
ssh = null;
}
第一次,當我將代碼作為耳文件部署到oracle weblogic服務器上時,它是工作文件,並且創建了dmp文件並將sftpd到所需位置,但是從第二次開始,我收到錯誤消息: 錯誤:權限被拒絕
請幫忙..
首先,永遠不要使用chmod -R 777
就像將數據發布給有權訪問該計算機的任何人一樣,沒有任何問題。 如果您使用它來調試問題,那么可以,但是不要忘了將其改回(或者擺脫它;您根本不需要它)。
要調試“權限被拒絕”錯誤,您需要有權訪問計算機。 在計算機上,您需要以遇到錯誤的用戶身份登錄(不要以root用戶或其他用戶身份嘗試)。
以該用戶身份,嘗試訪問您無法訪問的路徑中的每個文件夾。 因此,如果/srv/www/foo/bar/x/y/z/file.txt
失敗,則需要
ls /srv
ls /srv/www/
ls /srv/www/foo/
ls /srv/www/foo/bar/
ls /srv/www/foo/bar/x/
ls /srv/www/foo/bar/x/y/
ls /srv/www/foo/bar/x/y/z/
ls /srv/www/foo/bar/x/y/z/file.txt
按此順序執行。 查找第一個失敗的命令,然后檢查為什么該用戶沒有問題文件夾的權限。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.