Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > File Transfer

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 09-20-2016, 02:56 PM
edsoho edsoho is offline
Registered User
 
Join Date: Sep 2016
Posts: 2
What is the suggested way to upload local file to remote?

I'm using VRALib with .net c# and having issues to upload

I am using .Put method from IFileSystemObject and also tried .Copy, both fail

the error is: "Failed to set the permissions or timestamp on the destination file: Access is denied."

I am able to upload file through SecureFX just fine with the same credentials. I'm having this issue only using VRAlib

any comments are welcome, thanks
Reply With Quote
  #2  
Old 09-20-2016, 03:14 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,099
Quote:
Originally Posted by edsoho View Post
I am using .Put method from IFileSystemObject and also tried .Copy, both fail... the error is: "Failed to set the permissions or timestamp on the destination file: Access is denied."
The .Put method is a wrapper around a more powerful and controllable FileTransferObject.

.Put is simple to use, but doesn't provide you with the capability you need to control whether or not VRALib tries to preserve time-stamps and permissions on the uploaded file. The server you're uploading to doesn't allow you to set the timestamp and/or the permissions on the uploaded file. SecureFX doesn't balk when these are denied, but VRALib's .Put method fails.

To work around the permission denied error being returned by the SFTP server, you will need to use the FileTransferObject rather than the IFileSystemObject to perform the transfer. You will need to use the PreservePermissions and PreserveTimestamps properties of the object to disable the attempt to preserve these properties/perms.

Does this help?

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #3  
Old 09-20-2016, 03:25 PM
edsoho edsoho is offline
Registered User
 
Join Date: Sep 2016
Posts: 2
Hi Jake

thanks for the fast reply and for the detailed explanation about his issue.

I've read about the FileTransferObject in previous posts before that could be used instead of .Put from IFileSystemObject.

However, it's been quite challenging to understand how a FileTransferObject works with a current Connection object

The Help installed with the Vandyke tools is quite simple and doesn't clarify much

Is there any official, more complete resource place I could find my answer?

thanks
Reply With Quote
  #4  
Old 09-20-2016, 03:45 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,099
Quote:
Originally Posted by edsoho View Post
I've read about the FileTransferObject in previous posts before that could be used instead of .Put from IFileSystemObject.

However, it's been quite challenging to understand how a FileTransferObject works with a current Connection object

The Help installed with the Vandyke tools is quite simple and doesn't clarify much

Is there any official, more complete resource place I could find my answer?
We're available to answer specific questions.

Where are you stuck currently in your attempts to use the FileTransferObject?

Here's an example of how the FileTransferObject is used in VBScript (I don't have a C# .NET example, but you can get the idea, perhaps).

Code:
' Get a reference to the local file system object
Set objLocalFSO = CreateObject("Scripting.FileSystemObject")

' Let's log debugging info to the following file...
strLogFile = "C:\Temp\VRAlibDebug.txt"

' Keep a backup of prior log file with each instance of this script (comment or
' remove the following 3 lines of code if you want a running log of all VRALIB
' operations from this script.
If objLocalFSO.FileExists(strLogFile) Then
    On Error Resume Next
        objLocalFSO.DeleteFile strLogFile & ".bak"
        objLocalFSO.MoveFile strLogFile, strLogFile & ".bak"
    On Error Goto 0
End If

' Set up a VRALIB "Connection" object that we can use to establish an SSH
' transport to a remote secure shell server
Set objSession = CreateObject("vralib.Connection")

objSession.AuthenticationMethods = "publickey"
objSession.AutoAcceptHostkey = True

' Enable debugging level 3 for troubleshooting any problems that
' might occur
objSession.DebugLevel = 3
objSession.DebugLogFile = strLogFile

' set up username and public/private key to use for authentication
objSession.UserName = "user"
objSession.SetPrivateKeyFile "C:\temp\identity", "P4$$phrase"
objSession.TryAllAgentKeys = True

Dim nError, strErr, strLocalPath
On Error Resume Next
    ' Establish the connection to the remote server
    objSession.Connect "192.168.0.1"
    nError = Err.Number
    strErr = Err.Description
On Error Goto 0

' Check for errors connecting...
If nError <> 0 Then
    ' Exit with error code
    WScript.Quit nError
End If

' ##############################################################################
' Example upload using the FileTransferObject
Set objFTO = CreateObject("vralib.FileTransferObject")
' Specify which file to upload: 
objFTO.SourcePath = "C:\temp\afile.txt"

' Hook up the remote file system object:
objFTO.DestinationFileSystemObject = objSession.FileSystemObject
' Specify the path to the folder where the file will be placed on the remote
' system.
objFTO.DestinationPath = "./foldername/afile.txt"
' Replace existing file, if any, on the remote side
objFTO.OverWrite = True
' Delete source file if the the upload was successful
objFTO.AutoDeleteSourceFiles = True

' Execute the file transfer operation defined above
On Error Resume Next
    objFTO.Execute
    nError = Err.Number
    strErr = Err.Description
On Error Goto 0

' Check for errors during transfer process...
If nError <> 0 Then
    ' Exit with error code
    WScript.Quit nError
End If

' ##############################################################################
' Example download using the FileTransferObject
Set objFTO = CreateObject("vralib.FileTransferObject")

' Hook up the remote file system object:
objFTO.SourceFileSystemObject = objSession.FileSystemObject
' Specify the path to the file that will be downloaded
objFTO.SourcePath = "./foldername/afile.txt"
' Replace existing file, if any, on the local side
objFTO.OverWrite = True
' Delete source file if the the download was successful
objFTO.AutoDeleteSourceFiles = True

' Specify path to folder where file will be placed on local system: 
objFTO.DestinationPath = "C:\temp\afile.txt"

' Execute the file transfer operation defined above
On Error Resume Next
    objFTO.Execute
    nError = Err.Number
    strErr = Err.Description
On Error Goto 0

' Check for errors during transfer process...
If nError <> 0 Then
    ' Exit with error code
    WScript.Quit nError
End If
The example doesn't explicitly show the use of the PreservePermissions and PreserveTimestamps properties, but you can see the pattern that you'd simply set these properties prior to calling "Execute" on the FTO. For example:
Code:
...
objFTO.PreservePermissions = False
objFTO.PreserveTimestamps = False
...
objFTO.Execute
Does this help?

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
Reply

Tags
upload , vralib

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 08:33 PM.