Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/313.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
使用ganymed/Java的SCP-没有这样的文件或目录?_Java_Scp - Fatal编程技术网

使用ganymed/Java的SCP-没有这样的文件或目录?

使用ganymed/Java的SCP-没有这样的文件或目录?,java,scp,Java,Scp,我正在尝试使用Java的Ganymed将文件从Windows服务器(安装了openSSH/Cygwin)SCP到Mac。我以编程方式获取当前目录的路径,但出于某种原因,它表示找不到本地目录。这条路绝对正确,所以我不知道发生了什么 Connection conn; String hostname = "10.10.1.2"; String username = "myuser"; String password = "mypass"; String localDir = System.getPr

我正在尝试使用Java的Ganymed将文件从Windows服务器(安装了openSSH/Cygwin)SCP到Mac。我以编程方式获取当前目录的路径,但出于某种原因,它表示找不到本地目录。这条路绝对正确,所以我不知道发生了什么

Connection conn;
String hostname = "10.10.1.2";
String username = "myuser";
String password = "mypass";

String localDir = System.getProperty("user.dir");
String remoteFile = "/path/to/the/file.txt";

Connection conn = new Connection(hostname);
conn.connect();
conn.authenticateWithPassword(username, password);
SCPClient scp = conn.createSCPClient();
scp.put(remoteFile, 2815, localDir, "0644");
conn.close();

因为我使用的是.getProperty方法,所以我知道路径是正确的。另外,我有单独的方法,可以通过ssh连接到windows机器并启动/停止服务,因此我知道凭据是正确的。那么为什么这不起作用呢?谢谢

我收集到这段代码在Mac电脑上运行,它应该把一个文件从Windows系统复制到Mac电脑上

scp.put(remoteFile, 2815, localDir, "0644");
该操作将文件从本地系统传输到远程系统。您要调用,它将文件从远程系统传输到本地系统。将put()行替换为以下内容:

scp.get(remoteFile, localDir);

首先,谢谢!不知道我怎么会错过。不过,我仍然有问题,结果证明原因是引用的版本比引用的版本旧。我在pom.xml中切换到版本
build210
,并且能够像编写的那样使用ganymed,没有任何问题。(添加此项供将来参考)scp.put我尝试过,但缺乏关于如何使用它的真实信息,我最终使用了SFTPv3Client,这也是哈德逊对build260所做更改的一部分