Import com#jcraft#jsch#Channel
Import com#jcraft#jsch#ChannelSftp
Import com#jcraft#jsch#Jsch
Import com#jcraft#jsch#JSchException
Import com#jcraft#jsch#Session
Import com#jcraft#jsch#SftpException
Import java#util#Vector
Public Sub main(ByJava args() As String)
Dim myArgs() As String
myArgs = args
Dim sResult As String = "" '// Generic return value
Dim sHostName As String
Dim sUserName As String
Dim sPassword As String
Dim sDirectory As String
Dim prpConfig As New Properties()
Dim sshDemo As JSch
Dim sesSSH As Session
Dim chnSFTP As Channel
Dim chnsftpFiles As ChannelSftp
Dim vFiles As Vector
Dim nNumberOfFiles As Integer
Dim nthFile As Integer
Dim sNthFile As String
On Error Goto ErrHandler
prpConfig = New Properties()
System.out.println( "Setting strict host key checking off" )
prpConfig.put( "StrictHostKeyChecking", "no" )
sHostName = "files.mysite.com"
sUserName = "myusername"
sPassword = "mypassword"
sDirectory = "/dis_folder/and/dat_folder/and/deoder_folder_dere"
System.out.println( "Creating JSCH instance" )
sshDemo = New JSch()
System.out.println( "Getting a session " & "Username: " & sUserName & ", " & " Hostname: " & sHostName )
sesSSH = sshDemo.getSession( sUserName, sHostName, 22 )
System.out.println( "Setting the config property for the session" )
sesSSH.setConfig( prpConfig )
sesSSH.setPassword( sPassword )
System.out.println( "Connecting the ssh session" )
sesSSH.connect()
System.out.println( "Opening an sftp channel" )
chnSFTP = sesSSH.openChannel( "sftp" )
System.out.println( "Connecting the channel" )
chnSFTP.connect()
chnsftpFiles = Cast( chnSFTP, ChannelSftp )
chnsftpFiles.cd( sDirectory )
vFiles = chnsftpFiles.ls( "*" )
nNumberOfFiles = vFiles.size
System.out.println( "Directory " & sDirectory & " " & "has " & nNumberOfFiles )
For nthFile = 1 To nNumberOfFiles
sNthFile = vFiles.get( nthFile ).toString
System.out.println( "Filename: & " & sNthFile )
Debug().Print( "Filename: & " & sNthFile )
Next 'nthFile = 1 To nNumberOfFiles
chnsftpFiles.disconnect
sesSSH.disconnect
'// Temporary breakpoint. Remove, after development.
sResult = sResult
Exit Sub
ErrHandler:
JabacoErrorManager( "JSCH_Example : " & Err.getClass.getName, "what the...? ", Err.getMessage )
End Sub