PowerBuilder
PowerBuilder
SCP Sync Tree Upload
See more SCP Examples
Synchronize local and remote directory trees by uploading newer or missing files to the remote server.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Ssh
string ls_Hostname
integer li_Port
oleobject loo_Scp
string ls_RemoteRoot
string ls_LocalRoot
integer li_BRecurse
integer li_Mode
li_Success = 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Ssh = create oleobject
li_rc = loo_Ssh.ConnectToNewObject("Chilkat.Ssh")
if li_rc < 0 then
destroy loo_Ssh
MessageBox("Error","Connecting to COM object failed")
return
end if
// Hostname may be an IP address or hostname:
ls_Hostname = "www.some-ssh-server.com"
li_Port = 22
// Connect to an SSH server:
li_Success = loo_Ssh.Connect(ls_Hostname,li_Port)
if li_Success <> 1 then
Write-Debug loo_Ssh.LastErrorText
destroy loo_Ssh
return
end if
// Wait a max of 5 seconds when reading responses..
loo_Ssh.IdleTimeoutMs = 5000
// Authenticate using login/password:
li_Success = loo_Ssh.AuthenticatePw("myLogin","myPassword")
if li_Success <> 1 then
Write-Debug loo_Ssh.LastErrorText
destroy loo_Ssh
return
end if
// Once the SSH object is connected and authenticated, we use it
// in our SCP object.
loo_Scp = create oleobject
li_rc = loo_Scp.ConnectToNewObject("Chilkat.Scp")
li_Success = loo_Scp.UseSsh(loo_Ssh)
if li_Success <> 1 then
Write-Debug loo_Scp.LastErrorText
destroy loo_Ssh
destroy loo_Scp
return
end if
// The remoteRoot is relative to the HOME directory of the SSH user account.
ls_RemoteRoot = "workspace/projectB"
ls_LocalRoot = "c:/aaworkarea/scp/workspace/projectB"
// Upload synchronization modes:
// mode=0: Upload all files
// mode=1: Upload all files that do not exist on the FTP server.
// mode=2: Upload newer or non-existant files.
// mode=3: Upload only newer files. If a file does not already exist on the FTP server, it is not uploaded.
// mode=4: transfer missing files or files with size differences.
// mode=5: same as mode 4, but also newer files.
// Additional files and directores can be excluded by setting the SyncMustNotMatch property.
// The SyncMustNotMatch patterns apply only to the final filename or directory part of a path.
// If a directory matches, then it will not be traversed in a recursive traversal.
//
loo_Scp.SyncMustNotMatch = "*.o;*.obj;*.log; temp"
// The SyncMustMatch property can be set to restrict the files uploaded to only those
// matching at least one pattern in a set.
loo_Scp.SyncMustMatch = "*.cpp; *.h"
// Do the recursive sync to upload newer or non-existant files:
li_BRecurse = 1
li_Mode = 2
li_Success = loo_Scp.SyncTreeUpload(ls_LocalRoot,ls_RemoteRoot,li_Mode,li_BRecurse)
if li_Success <> 1 then
Write-Debug loo_Scp.LastErrorText
destroy loo_Ssh
destroy loo_Scp
return
end if
// The files actually uploaded can be examined in the SyncedFiles property.
// It is a string property that contains the relative path, one per line, of each
// file uploaded.
Write-Debug "Files uploaded: "
Write-Debug loo_Scp.SyncedFiles
Write-Debug "----"
Write-Debug "SCP sync upload success."
// Disconnect
loo_Ssh.Disconnect()
destroy loo_Ssh
destroy loo_Scp