Java 如何使用JSch库中的代理传输文件
我想将文件传输到远程位置,我必须为此使用代理服务器。我可以通过以下命令连接到FTP位置: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
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))面对同样的问题这对我起作用了。非常感谢。