Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Java';调用PSCP时,如何遍历到父目录;什么是ProcessBuilder?_Java_Unix_Putty_Pscp - Fatal编程技术网

使用Java';调用PSCP时,如何遍历到父目录;什么是ProcessBuilder?

使用Java';调用PSCP时,如何遍历到父目录;什么是ProcessBuilder?,java,unix,putty,pscp,Java,Unix,Putty,Pscp,我使用以下代码从Java调用pscp: public static ArrayList<String> runWindowsCommand(String... args) throws WindowsCmdFault { try { ProcessBuilder pb = new ProcessBuilder(args); Process p = pb.start(); //...

我使用以下代码从Java调用pscp:

public static ArrayList<String> runWindowsCommand(String... args) throws WindowsCmdFault {
        try {
              ProcessBuilder pb = new ProcessBuilder(args);
              Process p = pb.start();


              //...
              //... code to fetch the output and return it back


            }catch (IOException | InterruptedException e) {
              e.printStackTrace();
            }

    }
这将执行良好,并显示以下输出:

Arraylist returned (output) = 
[, file_to_be_transferred.txt                | 3 kB |   2.7 kB/s | ETA: 00:00:00 | 100%]
看来转移是成功的。除了当我通过putty登录到远程unix服务器并检查该文件时,它显示没有更新任何内容。

文件的权限已设置为666。

当我直接在cmd提示符上执行相同的命令(我们发送给函数)时,它会给出相同的输出,并且文件实际上会被传输

当我通过上面给出的Java代码运行相同的命令时,文件实际上并没有被传输

为什么PSCP不传输文件

最新消息:经过进一步调查并感谢@Martin Prikryl,我能够将这个问题缩小到根本原因。

根本原因: 问题是,当从PSCP建立用户连接时,默认情况下它会连接到
(root)/home/username

我们需要遍历的目录位于

(root)/www/....lengthy/folder/here .
剩余问题:

连接后,我正在尝试向上遍历文件夹。我试图添加一个双周期,以便在提供路径之前向上遍历根。但它不起作用

我正在尝试使用pscp作为远程主机名:

../../www/..lengthy/folder/here 
但由于某些奇怪的原因,当通过Java执行时,它失败了,但通过cmd提示符工作


在包含实际路径之前,如何添加包含第二个父级的远程路径?

使用Java+PSCP时似乎有一些限制。我通过将文件上传到默认目录解决了这个问题。之后,我通过putty的命令行建立连接,并将文件传输到所需的目标。我把答案放在这里

../../www/..lengthy/folder/here