我正在使用 Coldfusion 9。我已验证 sFTP 主机有效,并且可以使用“CyberDuck”进行连接。端口不是标准的 21 (ftp) 或 22 (ssh)
<cfftp
username= "myysername"
password= "mypassword"
port= "6589"
server= "ftphost.com"
secure= "yes"
name= "ftpconnection"
action= "open" />
<cfdump var="#ftpconnection#">
大约 1 分钟后的结果是:
com.jcraft.jsch.JSchException: Session.connect: java.net.SocketTimeoutException: Read timed out
at com.jcraft.jsch.Session.connect(Unknown Source)
at com.jcraft.jsch.Session.connect(Unknown Source)
at coldfusion.tagext.net.SftpHandler.getConnection(SftpHandler.java:265)
at coldfusion.tagext.net.SftpHandler.createConnection(SftpHandler.java:76)
at coldfusion.tagext.net.FtpTag.doStartTag(FtpTag.java:675)
at coldfusion.runtime.CfJspPage._emptyTcfTag(CfJspPage.java:2722)
我还尝试通过手动调用 JSCH 类(http://www.jcraft.com/jsch/examples/Sftp.java.html)来建立这种连接,但无济于事。
问题是,为什么在代码中会出现这种超时,但在使用 CyberDuck 这样的程序时却不会?
编辑以添加 CF-Java 代码
jsch = CreateObject("java", "com.jcraft.jsch.JSch");
jsession = CreateObject("java", "com.jcraft.jsch.Session");
jChannel = CreateObject("java", "com.jcraft.jsch.Channel");
jChannelSFTP = CreateObject("java", "com.jcraft.jsch.ChannelSftp");
jUserInfo = CreateObject("java", "com.jcraft.jsch.UserInfo");
jProperties = CreateObject("java", "java.util.Properties");
jLogger = CreateObject("java", "com.jcraft.jsch.Logger");
host = "ftphost.com";
username = "myusername";
portNumber = "6589";
javaCast("String", "host");
javaCast("String", "username");
/* *********************** */
jProperties.put("StrictHostKeyChecking", "no");
jsession = jsch.getSession(username, host, portNumber);
jsession.setPassword("mypassword");
jsession.setPort(6589);
jsession.setUserInfo(jUserInfo);
jsession.setConfig(jProperties);
writeOutput("Connect ...");
getPageContext().getOut().flush();
jsession.connect();
writeOutput("done <br>");
这段代码本身没有错误,但 connect() 方法永远不会“返回”:
connection is closed by foreign host
The error occurred in /Library/WebServer/Coldfusion/SFTP/index.cfm: line 53
51 : writeOutput("Connect ...");
52 : getPageContext().getOut().flush();
53 : jsession.connect();
54 : writeOutput("done <br>");
55 :
编辑显示 CYBERDUCK 连接日志
220 Service ready for new user.
AUTH TLS
234 Command AUTH okay; starting TLS connection.
USER myusername
331 User name okay, need password for myusername.
PASS ********
230 User logged in, proceed.
PBSZ 0
200 Command PBSZ okay.
PROT P
200 Command PROT okay.
FEAT
[ ... ]
OPTS UTF8 ON
200 Command OPTS okay.
NOOP
200 Command NOOP okay.
SYST
215 UNIX Type: Apache FtpServer
STAT /root
200--rw------- 1 SMG TGMS 263375 Nov 25 01:35 afile.txt