java jsch isdir_JSch - 服务器“home”路径始终为FreeSSHd的“/”,无法更改目录

谢谢大家的意见。我安装FreeSSHd并设置默认目录,然后,当我尝试通过控制台ssh进行连接时,目录是“/”,我在编写chdir但目录是:C:\ Windows \ system32 \这是很迷茫......

我的Java代码:

public void recursiveFolderUpload(String sourcePath, String destinationPath) throws FileNotFoundException {

if (c == null || session == null || !session.isConnected() || !c.isConnected()) {

log.debug("Connection to server is closed. Open it first.");

}

try {

// c.put(sourceFile, destinationFile);

// log.info("Upload successfull.");

File sourceFile = new File(sourcePath);

if (sourceFile.isFile()) {

// copy if it is a file

c.cd(destinationPath);

if (!sourceFile.getName().endsWith("."))

c.put(new FileInputStream(sourceFile), sourceFile.getName(), c.OVERWRITE);

} else {

log.info("Inside else " + sourceFile.getName());

File[] files = sourceFile.listFiles();

if (files != null && !sourceFile.getName().startsWith(".")) {

log.info("Directory remote server: " + c.pwd());

c.cd(destinationPath);

SftpATTRS attrs = null;

// check if the directory is already existing

try {

attrs = c.stat(destinationPath + sourceFile.getName());

} catch (Exception e) {

log.warn(destinationPath + sourceFile.getName() + " not found");

//e.printStackTrace();

}

// else create a directory

if (attrs != null) {

log.info("Directory exists IsDir : " + attrs.isDir());

} else {

log.info("Creating dir /" + sourceFile.getName());

c.mkdir(sourceFile.getName());

}

for (File f : files) {

if(!f.getName().contains(".dtd")){

log.info("Uploading file: " + f.getAbsoluteFile());

recursiveFolderUpload(f.getAbsolutePath(), destinationPath + sourceFile.getName() + "/");

}

}

}

}

} catch (SftpException e) {

e.printStackTrace();

}

}

我的解决办法是只把 “/” EN输入参数方法的DestinationPath的称为recursiveFolderUpload 再次

properties.host = IP

properties.user = user

properties.pass = pass

properties.port = port

properties.dir =/ ---> This points to the directory configured by default in opensshd within windows

感谢这么多的寄托都:

换句话说,我的属性文件不是这样。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值