Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/369.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 如何使用JSch库中的代理传输文件_Java_Sftp_File Transfer_Jsch_Http Proxy - Fatal编程技术网

Java 如何使用JSch库中的代理传输文件

Java 如何使用JSch库中的代理传输文件,java,sftp,file-transfer,jsch,http-proxy,Java,Sftp,File Transfer,Jsch,Http Proxy,我想将文件传输到远程位置,我必须为此使用代理服务器。我可以通过以下命令连接到FTP位置: sftp-o“ProxyCommand/usr/bin/nc-X connect-X:%h%p”username@ftp_server: 但我想自动化这个文件传输过程,我正在使用JSch for SFTP,代码片段如下: String sourceFile = sourceDir + fileName; JSch jsch = new JSch(); int port = Integer.parseInt

我想将文件传输到远程位置,我必须为此使用代理服务器。我可以通过以下命令连接到FTP位置:

sftp-o“ProxyCommand/usr/bin/nc-X connect-X:%h%p”username@ftp_server:
但我想自动化这个文件传输过程,我正在使用JSch for SFTP,代码片段如下:

String sourceFile = sourceDir + fileName;
JSch jsch = new JSch();
int port = Integer.parseInt(getFtpPort());
Session session = jsch.getSession(getUserName(), getHost(), port);
session.setConfig(STRICT_HOST_CHECKING, ANSWER);
session.setProxy(new ProxyHTTP(<proxy_host>, <proxy_port>));
session.setPassword(getPassword());
session.connect();
Channel channel = session.openChannel(FILE_PROTOCOL);
channel.connect();
sftpChannel = (ChannelSftp) channel;
sftpChannel.cd(desDir);
File fileToTransfer =  new File(sourceFile);
sftpChannel.put(new FileInputStream(fileToTransfer), fileName);
使用 session.setProxy(新的ProxySOCKS5(,)

而不是
proxyHTTP

希望它对你有用。。。 它对我有用这对我有用

JSch jsch = new JSch();
java.util.Properties config = new java.util.Properties();
Session session = jsch.getSession(RemoteUserName, RemoteIpAddr, RemotePortNo);
session.setPassword(RemotePassword);
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.setProxy(new ProxyHTTP(ProxyName, ProxyPort));
session.connect();
ProxyHTTP  proxy = new ProxyHTTP("192.168.10.1",80)
proxy.setUserPasswd("username","password");
session.setProxy(proxy);
这对我有用

ProxyHTTP  proxy = new ProxyHTTP("192.168.10.1",80)
proxy.setUserPasswd("username","password");
session.setProxy(proxy);

你有没有想过这个?使用HTTP Proxy
session.setProxy(新的ProxyHTTP(proxyName,proxyPort))面对同样的问题