sftp/Simple.wsf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | <?xml version= "1.0" ?> <package> <job> <reference object= "sfFTPLib.SFTPConnection" /> <reference object= "sfFTPLib.SSHConnection" /> <script language= "VBScript" > <![CDATA[ '/////////////////////////////////////////////////////////////////////////////////// '// '// Simple '// '// Purpose: '// - Connects to remote server. '// - Reads the current directory. '// - Downloads a file. '// - Uploads a file. '// '// Technical support: support@smartftp.com '// '/////////////////////////////////////////////////////////////////////////////////// Dim objGlobal Set objGlobal = CreateObject( "sfFTPLib.Global" ) 'objGlobal.LoadLicense("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX") Dim obj Set obj = CreateObject( "sfFTPLib.SSHConnection" ) ' Settings WScript.Echo "Please change the settings in the script for this demo." & vbCrLf obj.Host = "localhost" obj.Username = "user" obj.Password = "password" obj.Port = 22 ' Enable logging 'Dim fileLogger 'Set fileLogger = obj.SetFileLogger() 'fileLogger.File = "ssh.log" ' Public Key Authentication ' Uncomment to load private key 'Dim oKeyManager 'Set oKeyManager = CreateObject("sfFTPLib.KeyManager") 'Dim oPrivateKey 'Set oPrivateKey = oKeyManager.LoadFile("Identity", "password") 'obj.PrivateKey = oPrivateKey ' Set Authenciation Methods ' Uncomment to set authentication methods Dim arAuthentications(1) arAuthentications(0) = ftpSSHAuthenticationPassword arAuthentications(1) = ftpSSHAuthenticationPublicKey 'obj.Authentications = arAuthentications ' Limit Encryptions ' Uncomment to limit encryptions Dim arEncryptions(3) arEncryptions(0) = ftpEncryption3DES arEncryptions(1) = ftpEncryptionAES256 arEncryptions(2) = ftpEncryptionAES192 arEncryptions(3) = ftpEncryptionAES128 'obj.Encryptions = arEncryptions ' Limit Compression Algorithms Dim arCompressions(1) arCompressions(0) = ftpSSHCompressionzlibopenssh arCompressions(1) = ftpSSHCompressionNone 'obj.Compressions = arCompressions obj.Connect() WScript.Echo "Connect() successful. RemoteId=" & obj.ServerState.RemoteId & vbCrLf Dim objSFTP Set objSFTP = obj.CreateSFTPConnection() 'Dim fileLogger2 'Set fileLogger2 = objSFTP.SetFileLogger() 'fileLogger2.File = "sftp.log" objSFTP.Connect() ' Always get the current path Dim strCurrentPath strCurrentPath = objSFTP.RealPath( "." ) WScript.Echo "Current Path = " & strCurrentPath & vbCrLf ' Reading the directory Dim oItems Set oItems = objSFTP.ReadDirectory(strCurrentPath) strMsg = strMsg & "Directory: " & strCurrentPath & " Count: " & oItems.Count & vbCrLf Dim oItem For Each oItem In oItems strMsg = strMsg & " Type=" & oItem.Type & ", Name=" & oItem.Name If oItem.Type = ftpItemTypeRegularFile Then strMsg = strMsg & ", Size=" & oItem.SizeLo End If If oItem.IsValidAttribute(ftpFTPItemAttributeModifyTime) Then strMsg = strMsg & ", ModifyTime=" & CDate (oItem.ModifyTimeAsDate) End If strMsg = strMsg & vbCrLf Next WScript.Echo strMsg ' Downloading a file Dim strRemoteFile strRemoteFile = "/C/Archive/date.zip" Dim strLocalFile strLocalFile = "Download\date.zip" WScript.Echo "Please change the paths in the script for the DownloadFile demo." & vbCrLf call objSFTP.DownloadFile(strRemoteFile, strLocalFile, 0,0) WScript.Echo "" "" & strRemoteFile & "" " successfully downloaded to " "" & strLocalFile & "" "" & vbCrLf ' Stat. Trying to get file size Set oItem = objSFTP.Stat(strRemoteFile, ftpSFTPItemAttributeSize) ' TODO: Use IsValidAttribute to check if the Size attribute is valid. WScript.Echo "File Size = " & oItem.SizeLo ' Uploading a file strRemoteFile = "/C/Archive/dateupload.zip" strLocalFile = "Download\date.zip" WScript.Echo "Please change the paths in the script for the UploadFile demo." & vbCrLf call objSFTP.UploadFile(strLocalFile, strRemoteFile, ftpDataTransferTypeImage, 0,0) WScript.Echo "" "" & strLocalFile & "" " successfully uploaded to " "" & strRemoteFile & "" "" & vbCrLf ]]> </script> </job> </package> |