谢谢大家的意见。我安装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
感谢这么多的寄托都:
换句话说,我的属性文件不是这样。