2

I am using Coldfusion 9. I have verified that the sFTP host is valid and I can connect using "CyberDuck". The port is not the standard 21 (ftp) or 22 (ssh)

<cfftp 
    username=   "myysername"
    password=   "mypassword"
    port=       "6589"
    server=     "ftphost.com"
    secure=     "yes"
    name=       "ftpconnection"
    action=     "open" />

<cfdump var="#ftpconnection#">

The result, after about 1 minute is :

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)

I have also tried building this connection by calling the JSCH classes ( http://www.jcraft.com/jsch/examples/Sftp.java.html ) manually, but to no avail.

The question is, why is this timing out in code, but not when using a program like CyberDuck ?

EDIT TO ADD CF-Java code

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>");

This code doesn't error per se, but the connect() method never "returns" :

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 : 

EDITED TO SHOW CYBERDUCK CONNECTION LOG

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
Brian
  • 161
  • 1
  • 13
  • does this post help any? http://stackoverflow.com/questions/14617/java-what-is-the-best-way-to-sftp-a-file-from-a-server – genericHCU Nov 26 '12 at 23:23
  • I edited my original post to show the exact CF-Java that I used when I said I tried calling the JSCH classes manually. – Brian Nov 27 '12 at 03:27
  • Your example only shows the opening of an ftp connection. Are you using that connection at all? Perhaps the ftp server is disconnecting due to an inactivity timeout. – Miguel-F Nov 27 '12 at 13:17
  • Miguel-F In the second example, where i use CreateObject(), it does not appear to connect. The code times out and an error is thrown at line 53. To me, that means the connect() method never returns and therefore the code below it is not executed. The first example using cfml, times out and throws an error on the tag. There again, it doesn't seem to return to allow me to continue executing code. – Brian Nov 27 '12 at 13:32
  • When you connected using "CyberDuck" was it from the server with ColdFusion on it? – Miguel-F Nov 27 '12 at 16:58
  • Miguel-F, Yes, CyberDuck is running on the same machine as CF. Edited in the original question is the verbose output created by CyberDuck when successfully connecting to the SFTP server. Thank you for your follow ups – Brian Nov 27 '12 at 17:25
  • Did you see this in the docs about opening secure ftp connections? [cfftp: Opening and closing secure FTP server connections](http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-72fa.html). Also when tagging someone in these comments you need to proceed their username with the `@` symbol or else they do not get notified. Just FYI on that. – Miguel-F Nov 27 '12 at 18:41
  • Sorry forgot to mention what I saw in that doc. Have you tried adding the `fingerprint` attribute? And have you tried adding the `stopOnError` attribute to potentially get some debugging info. It also appears that you are using the `name` attribute but should be using the `connection` attribute. Just some thoughts. – Miguel-F Nov 27 '12 at 18:49
  • @Miguel-F i will try these suggestions this evening. Thank you for all your help. I will move on to another solution if these suggestions don't work. – Brian Nov 28 '12 at 01:08
  • @Miguel-F Since you kept up with me I figured I'd give a sort of conclusion to my issue. So this isn't the solution, but I have finally been able to connect and list files. Downloading files is an issue. I ended up writing this using C#. I manually send the commands that I see using CyberDuck and it seems to work. I think I am having a firewall issue in my office that prevents me from downloading. But anyway... That's where it stands. – Brian Nov 29 '12 at 21:00
  • Cool, thanks for the update Brian. I'm a little bummed that you couldn't get it to work using ColdFusion though. I'm sure there is a way. ??? – Miguel-F Nov 29 '12 at 21:45

2 Answers2

2

I had a similar issue and the root cause was ColdFusion services was not running as local user. If you run CF in Console mode you will see that the FTP site is waiting for the user to accept the authentication. On the CF side it just times out.

To resolve this, I added these 2 lines right before the cfftp tag.

<cfset _jsch = CreateObject('java','com.jcraft.jsch.JSch')>
<cfset _jsch.setConfig("PreferredAuthentications", "publickey,keyboard-interactive,password")>
cma0651
  • 31
  • 6
0

Have you tried changing the timeout value of the cfhttp. You can change the default timeout by using the <cfhttp timeout="240"> and specifying in seconds.

Computerman1597
  • 214
  • 3
  • 10