Here is part of a wrapper we have written for the jsch library. The
rest of the component deals with stuff that is specific to our
application.
hth
<cffunction name="init" access="public" output="false" returntype="SFTPManager">
<cfargument name="username" required="true" type="string">
<cfargument name="password" required="true" type="string">
<cfargument name="hostname" required="true" type="string">
<cfargument name="port" required="true" type="numeric">
<cfargument name="basePath" required="true" type="string">
<cfargument name="dsn" required="true" type="string">
<!--- Init objects --->
<cfset variables.JSch = createObject('Java','com.jcraft.jsch.JSch')>
<cfset variables.userInfo =
createObject('Java','com.jcraft.jsch.UserInfo')>
<cfset variables.config =
createObject('Java','java.util.Properties').init()>
<!--- Init variables --->
<cfset variables.username = arguments.username>
<cfset variables.password = arguments.password>
<cfset variables.hostname = arguments.hostname>
<cfset variables.port = arguments.port>
<cfset variables.basePath = arguments.basePath>
<cfset variables.dsn = arguments.dsn>
<cfreturn this>
</cffunction>
<cffunction name="upload" access="public" output="false" returntype="boolean">
<cfargument name="file" required="true" type="string">
<cfargument name="path" required="true" type="string">
<cfset var SFTPSession = "">
<cfset var channel = "">
<cfset var putPath = "#variables.basePath#/#arguments.path#">
<cfset var listPath = "#arguments.path#">
<cfset var listEle = "">
<cfset var dirList = "">
<cfset var fileName = "">
<cfset var i = "">
<cfset var success = false>
<cfset var xBasePath = "">
<cfset var lastInserted = "">
<cfset var arrayEle = "">
<cfset var arrayIndex = "">
<cfset var loopCount = "">
<cfset var isConnected = "">
<cfset variables.config.put("StrictHostKeyChecking", "no")>
<cfset SFTPSession = variables.JSch.getSession(variables.username,
variables.hostname, variables.port)>
<cfset SFTPSession.setPassword(variables.password)>
<cfset SFTPSession.setConfig(variables.config)>
<cfset SFTPSession.setUserInfo(variables.userInfo)>
<cftry>
<!--- Connect SSH session --->
<cfset SFTPSession.connect()>
<!--- <cfset isConnected = SFTPSession.isConnected()> --->
<!--- Set up SFTP channel --->
<cfset channel = SFTPSession.openChannel("sftp")>
<cfset channel.connect()>
<!--- Create remote directories... --->
<cfset xBasePath = variables.basePath>
<cfset lastInserted = "">
<cfset arrayEle = arrayNew(1)>
<cfset arrayIndex = 1>
<cfloop list="#listPath#" index="listEle" delimiters="/">
<cfif lastInserted EQ "">
<cfset arrayEle[arrayIndex] = xBasePath & "/" &
listEle>
<cfset lastInserted = xBasePath & "/" & listEle>
<cfset arrayIndex = arrayIndex + 1>
<cfelse>
<cfset arrayEle[arrayIndex] = lastInserted &
"/" & listEle>
<cfset lastInserted = lastInserted & "/" &
listEle>
<cfset arrayIndex = arrayIndex + 1>
</cfif>
</cfloop>
<cfloop index="loopCount" from="1" to="3">
<cftry>
<cfset channel.mkdir(arrayEle[loopCount])>
<cfcatch>
<!--- directory exists... --->
</cfcatch>
</cftry>
</cfloop>
<cfset channel.put("#arguments.file#",putPath)>
<!--- check if uploaded successfully --->
<cfset dirList = channel.ls(putPath)>
<cfset fileName = this.extractFileName(arguments.file)>
<cfloop from="1" to="#arrayLen(dirList)#" index="i">
<cfif dirList[i].getFilename() EQ fileName AND
dirList[i].getAttrs().getSize() EQ fileSize(arguments.file)>
<cfset success = true>
<cfbreak>
<cfelse>
<cfset success = false>
</cfif>
</cfloop>
<cfcatch>
<!--- Close everything down --->
<cfif isDefined('channel')>
<cftry>
<cfset channel.exit()>
<cfset channel.disconnect()>
<cfcatch>
<cfset success = false>
</cfcatch>
</cftry>
</cfif>
<cfset SFTPSession.disconnect()>
<cfset success = false>
</cfcatch>
</cftry>
<cftry>
<!--- Close everything down --->
<cfset channel.exit()>
<cfset channel.disconnect()>
<cfset SFTPSession.disconnect()>
<cfcatch>
</cfcatch>
</cftry>
<cfreturn success>
</cffunction>
On 7/4/07, Jim Rising <[EMAIL PROTECTED]> wrote:
> Jake,
>
> You could probably write a CFC wrapper for this:
>
> http://www.jscape.com/sftp/index.html
>
> That's really all that sftp.cfc is... It's a wrapper for Java Secure
> Channel:
>
> http://www.jcraft.com/jsch/
>
> Jim Rising
> Sr. Cold Fusion Developer
> ICGLink Inc.
> www.icglink.com
>
>
>
>
> -----Original Message-----
> From: Jake Pilgrim [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, July 03, 2007 11:36 AM
> To: CF-Talk
> Subject: FTPS
>
> Does anyone know of a way I can connect to an FTPS (FTP over SSL) server
> using coldfusion? I have seen the sftp.cfc download out there, but SFTP is a
> different protocol and this CFC doesn't seem to work.
>
> I would prefer a CFC/custom tag based solution, but I am able to run
> cfexecute so a command line solution could potentially work.
>
>
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
ColdFusion MX7 by AdobeĀ®
Dyncamically transform webcontent into Adobe PDF with new ColdFusion MX7.
Free Trial. http://www.adobe.com/products/coldfusion?sdid=RVJV
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:282920
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4