coldfusion sftp
I have added my cfsftp.cfc code in a zipped file to this blog. It is available as open source so please feel free to download and use.
This allows you to transfer files to a host like the [CFFTP] tag but uses the sftp secure protocol.
Looking forward to some feedback and hoping i haven't made any silly mistakes in the code or documentation.
There are several enhancements I have in mind for a v1.1.0 :-)
Let me know what you think.
An idea or two:
* key-based authentication
* 'mv' function to move/rename files
They've got v0.1.26 out that fixes a number of bugs, you might want to do a 1.0.1 release of your code with it bundled?
Excellent work, Michael.
I'll get that sorted. Mike
I have tried to use it, but am having problems getting the 'known_hosts' file onto the webserver.
We use IIS and ColdFusion.
Any help would be appreciated.
I looked for your email address, but could not find it.
Doug Jessee
If you have the latest version it will now create a know_hosts file for you.
Take a look at the example.cfm file in the distribution - it shows one way for you to implement this. See below,
<cftry>
<!--- try connection --->
<cfset mysftp.connect(host="yourhost",
username="youruser",
password="yourpass",
knownhostsfile="c:\known_hosts")>
<cfcatch type="any">
<!--- if failure is unknowhostkey then add it! --->
<cfif #findnocase("unknownhostkey",cfcatch.message)#>
<cfset mysftp.addhostkey(host="yourhost",
username="youruser",
password="yourpassword",
knownhostsfile="c:\known_hosts")>
<cfoutput>Adding host key for yourhost<br/></cfoutput>
<!--- retry connection --->
<cfset mysftp.connect(host="yourhost",
username="youruser",
password="yourpassword",
knownhostsfile="c:\known_hosts")>
</cfif>
</cfcatch>
</cftry>
<!--- you should be connected by the time you get here --->
Let me know if that helps.
I wonder if anyone have an idea about this problem,
I am using cfmx 7.01
OpenSSH 3.8.1p1 as Test SSH server
My ssh server work fine with other client
Any help will be greatly appreciated,
Alain
Mike T
Thanks for your patience.
Unfortunately I have an issue where the first use of the cfc/java object works fine, but any subsequent use just hangs up and never returns (no CF timeout either). After restarting the CF server, it works fine again, once, then hangs the next time. I'm testing with just a simple dir() call, and I do a disconnect() at the end of the session. This is on Windows 2K3 with CF 7. Seems to work for others, so I'm a bit baffled. Any ideas are apprecited.
Thanks,
-Max
Mike T
CFSFTP.connect;java.net.ConnectException: Connection refused: connect
Any ideas would be appreciated?
Thanks in advance.
Thanks for creating this. It has made my life SO much easier.
Best Regards
Cheers.
The code looks great. I have been testing it but I keep getting errors. Is there an email address I can use to send you the details of the errors? Till then I'll try fixing them. Cheers!! :)
Awesome work, Micheal.
I am having some trouble with using the code. I am trying to contact the youtube server. I am using the following code to connect:
<cfset mysftp = createobject("component","sftp").init()>
<cftry>
<cfset mysftp.connect(host="xxx.youtube.com",
username="abc",
passphrase="xxxxx",
privatekey="xxxyoutubekey",
knownhostsfile="xxx\known_hosts.cfm")>
<cfcatch type="any">
<cfif #findnocase("unknownhostkey",cfcatch.message)#>
<cfset mysftp.addhostkey(host="xxx.youtube.com",
username="abc",
passphrase="xxxxx",
privatekey="xxxyoutubekey",
knownhostsfile="xxx\known_hosts.cfm")>
<cfoutput>Adding host key for yourhost<br/></cfoutput>
<cfset mysftp.connect(host="xxx.youtube.com",
username="abc",
passphrase="xxxxx",
privatekey="xxxyoutubekey",
knownhostsfile="xxx\known_hosts.cfm")>
</cfif>
</cfcatch>
</cftry>
<cfset dirarray = mysftp.dir()>
<cfdump var="#dirarray#">
<cfset mysftp.disconnect()>
<cfset mysftp = "">
Once I run the file on my server, I am getting the following error:
CFSFTP.mkdir;Failure
can you please help me with this.
Thanks
Is there a chance that anyone has used this to connect to a FTPES ftp site?
FTPES - FTP over explicit TLS/SSL?
Thanks
how do I move back a directory (aka cd ..) or go to the root (aka cd \)? Once that is answered...this will be working like a charm!
Eric
Thsanks!
Eric
Did you by chance answer jared's question about FTPES?
"Is there a chance that anyone has used this to connect to a FTPES ftp site?
FTPES - FTP over explicit TLS/SSL?"
I can browser through the files and folder but having problem to use GET and PUT. Any ideas?
Below are the error observed.
--------------------------------------------------------------------------------
CFSFTP.put;Failure
The error occurred in C:\Inetpub\wwwroot\temp2\cfsftp\sftp.cfc: line 231
Called from C:\Inetpub\wwwroot\temp2\cfsftp\sftp.cfc: line 159
Called from C:\Inetpub\wwwroot\temp2\cfsftp\upload_file.cfm: line 100
229 : <cfif isDefined("result.id")>
230 : <cfset this_error = errormess[result.id]>
231 : <cfthrow message="CFSFTP.#arguments.who_failed#;#this_error#">
232 : </cfif>
233 : <cfif isDefined("result.message")>
I am getting an error "Variable mychannel is undefined" on this code:
<cfset dirarray = mysftp.dir()>
<cfdump var="#dirarray#">
and "OVERWRITE is undefined in MYCHANNEL" on this code <cfset mysftp.put("test.txt","test2.txt")>.
Thanks
Karen
CFSFTP.dir;Variable MYCHANNEL is undefined.
The error occurred in D:\Production\cfmx\web_applications\freerecall\sftp\sftp.cfc: line 234
Called from D:\Production\cfmx\web_applications\freerecall\sftp\sftp.cfc: line 121
Called from D:\Production\cfmx\web_applications\freerecall\sftp\dsp_Batch_page0006.cfm: line 29
232 : </cfif>
233 : <cfif isDefined("result.message")>
234 : <cfthrow message="CFSFTP.#arguments.who_failed#;#result.message#">
235 : </cfif>
236 : <cfthrow message="Unknown error in cfsftp">
Can you help? Is his an error with the known_hosts file?
Does anyone have any information on the following error:
Variable mychannel is undefined.