本文整理匯總了Java中com.jcraft.jsch.SftpException.printStackTrace方法的典型用法代碼示例。如果您正苦於以下問題:Java SftpException.printStackTrace方法的具體用法?Java SftpException.printStackTrace怎麽用?Java SftpException.printStackTrace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.jcraft.jsch.SftpException
的用法示例。
在下文中一共展示了SftpException.printStackTrace方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: delete
import com.jcraft.jsch.SftpException; //導入方法依賴的package包/類
@Override
public boolean delete(String srcPath) throws IOException {
System.out.println("delete "+getAbsolutePath(srcPath));
try {
EncFSFileInfo file = getFileInfo(srcPath);
if (!file.isDirectory()){
getSession().rm(getAbsolutePath(srcPath));
return true;
}
else {
getSession().rmdir(getAbsolutePath(srcPath));
return true;
}
} catch (SftpException e){
e.printStackTrace();
return false;
}
}
示例2: uploadFile
import com.jcraft.jsch.SftpException; //導入方法依賴的package包/類
/**
* Upload a single file to the sFTP server.未支持斷點續傳
*
* @param localFilePath Path of the file on local computer
* @param remoteDirectoryPath path of directory where the file will be stored
* @return true if the file was uploaded successfully, false otherwise
* @throws IOException if any network or IO error occurred.
*/
@Override
public void uploadFile(String localFilePath, String remoteDirectoryPath, boolean logProcess) throws FtpException {
if (!Paths.get(localFilePath).toFile().exists()) {
throw new FtpException("Unable to upload file, file does not exist : " + localFilePath);
}
if (!existsDirectory(remoteDirectoryPath))
createDirectory(remoteDirectoryPath);
try {
channel.put(localFilePath, remoteDirectoryPath);
} catch (SftpException e) {
e.printStackTrace();
throw new FtpException("Unable to upload file : " + localFilePath);
}
logger.info("upload file succeed : " + localFilePath);
}
示例3: createDirectory
import com.jcraft.jsch.SftpException; //導入方法依賴的package包/類
/**
* Create a directory and all missing parent-directories.
* <p>
* 設為 private ,不會有在服務器上僅僅創建文件夾的需求。
*
* @param remoteDirectoryPath
* @throws IOException
*/
private void createDirectory(String remoteDirectoryPath) {
String originalWorkingDirectory = getWorkingDirectory();
String[] folders = remoteDirectoryPath.split("/");
for (String folder : folders) {
if (folder.length() > 0) {
try {
channel.cd(folder);
} catch (SftpException e) {
try {
channel.mkdir(folder);
channel.cd(folder);
} catch (SftpException e1) {
e1.printStackTrace();
}
}
}
}
logger.info("create remote Directory '" + remoteDirectoryPath + "' succeed.");
//還原當前目錄
changeDirectory(originalWorkingDirectory);
}
示例4: put
import com.jcraft.jsch.SftpException; //導入方法依賴的package包/類
private void put(ChannelSftp cftp) throws SftpIOException {
// the below is just the replacement for one code line:
// cftp.put(srcFileName, dstFileName);
// (connected with #184068 - Instable remote unit tests failure)
int attempt = 0;
while (true) {
attempt++;
try {
cftp.put(parameters.srcFile.getAbsolutePath(), parameters.dstFileName);
if (attempt > 1) {
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "Success on attempt {0} to copy {1} to {2}:{3} :\n",
new Object[] {attempt, parameters.srcFile.getAbsolutePath(), execEnv, parameters.dstFileName});
}
}
return;
} catch (SftpException e) {
if (attempt > PUT_RETRY_COUNT) {
throw decorateSftpException(e, parameters.dstFileName);
} else {
if (LOG.isLoggable(Level.FINE) || attempt == 2) {
String message = String.format("Error on attempt %d to copy %s to %s:%s :\n", // NOI18N
attempt, parameters.srcFile.getAbsolutePath(), execEnv, parameters.dstFileName);
LOG.log(Level.FINE, message, e);
if (attempt == 2) {
Logger.fullThreadDump(message);
}
}
e.printStackTrace(System.err);
}
}
}
}
示例5: move
import com.jcraft.jsch.SftpException; //導入方法依賴的package包/類
@Override
public boolean move(String srcPath, String dstPath) throws IOException {
try {
getSession().rename(getAbsolutePath(srcPath),getAbsolutePath(dstPath));
return true;
} catch (SftpException e){
e.printStackTrace();
return false;
}
}
示例6: mkdir
import com.jcraft.jsch.SftpException; //導入方法依賴的package包/類
@Override
public boolean mkdir(String dirPath) throws IOException {
try {
getSession().mkdir(getAbsolutePath(dirPath));
return true;
} catch (SftpException e){
e.printStackTrace();
return false;
}
}
示例7: mkdirs
import com.jcraft.jsch.SftpException; //導入方法依賴的package包/類
@Override
public boolean mkdirs(String dirPath) throws IOException {
try {
getSession().mkdir(getAbsolutePath(dirPath));
return true;
} catch (SftpException e){
e.printStackTrace();
return false;
}
}
示例8: createFile
import com.jcraft.jsch.SftpException; //導入方法依賴的package包/類
@Override
public EncFSFileInfo createFile(String dstFilePath) throws IOException {
try {
getSession().put(getAbsolutePath(dstFilePath));
return getFileInfo(dstFilePath);
} catch (SftpException e){
e.printStackTrace();
return null;
}
}
示例9: fsDownload
import com.jcraft.jsch.SftpException; //導入方法依賴的package包/類
@Override
public InputStream fsDownload(String path, long startIndex) throws IOException {
System.out.println("download file "+path);
try {
BufferedInputStream is = new BufferedInputStream(getNewSession().get(getAbsolutePath(path)));
if (startIndex>0) is.skip(startIndex);
return is;
} catch (SftpException e){
e.printStackTrace();
return null;
}
}
示例10: fsUpload
import com.jcraft.jsch.SftpException; //導入方法依賴的package包/類
@Override
public OutputStream fsUpload(String path, long length) {
try {
return getNewSession().put(getAbsolutePath(path));
} catch (SftpException e){
e.printStackTrace();
return null;
}
}
示例11: mkdir
import com.jcraft.jsch.SftpException; //導入方法依賴的package包/類
public boolean mkdir(String path) {
try {
channelSftp.mkdir(path);
return true;
} catch (SftpException e) {
e.printStackTrace();
return (e.id != 3);
}
}
示例12: getCurrentDir
import com.jcraft.jsch.SftpException; //導入方法依賴的package包/類
public String getCurrentDir() {
try {
return channelSftp.pwd();
} catch (SftpException e) {
e.printStackTrace();
return "/";
}
}
示例13: existsFile
import com.jcraft.jsch.SftpException; //導入方法依賴的package包/類
/**
* Determines whether a file exists or not
* 如果是文件夾,返回 false
*
* @param remoteFilePath
* @return true if exists, false otherwise
* @throws IOException thrown if any I/O error occurred.
*/
@Override
public boolean existsFile(String remoteFilePath) {
try {
// System.out.println(channel.realpath(remoteFilePath));
SftpATTRS attrs = channel.stat(remoteFilePath);
return attrs.isReg();
} catch (SftpException e) {
e.printStackTrace();
return false;
}
// try {
// // ls 命令
// // 如果是文件夾或文件夾的符號鏈接,會進入該文件夾,進行列表,則文件個數會大於 1
// // 如果是文件,則隻會返回該文件本身,文件個數 =1
// Vector<LsEntry> lsEntries = channel.ls(remoteFilePath);
//
// for(LsEntry entry:lsEntries)
// System.out.println(entry.getFilename());
//
// return lsEntries.size() == 1;
// } catch (SftpException e) {
// e.printStackTrace();
// return false;
// }
}
示例14: setEncoding
import com.jcraft.jsch.SftpException; //導入方法依賴的package包/類
@Override
public void setEncoding(String encoding) {
try {
this.channel.setFilenameEncoding(encoding);
super.setEncoding(encoding);
} catch (SftpException e) {
e.printStackTrace();
}
}