Transferring not generating a VBScript error, but IsSuccess() returning false

Advertisement

Dan Curious
Donor
Joined:
Posts:
44
Location:
NY

Transferring not generating a VBScript error, but IsSuccess() returning false

I think I'm almost there. Can you check the code? Is there that stands out as a potential problem?

I tried it both with, and without transferResult.Check
' ...
' ...
 
On Error Resume Next
 
' Connect
Set session = WScript.CreateObject("WinSCP.Session")
 
 
Set sessionOptions = WScript.CreateObject("WinSCP.SessionOptions")
sessionOptions.Protocol = Protocol_SFTP
sessionOptions.HostName = "this.xx.gov"
sessionOptions.UserName = "username"
sessionOptions.Password = "xxxxxxx"
sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2....."
 
If Err.number  > 0 Then
    Transfer_Succeeded_b = False
    ErrorNumber = Err.number
    ErrorDescription = Err.Description
    ErrorSource = Err.Source
    Err.Clear
    Call LogError( "Problem Assigning Session settings " & File_From_s & " to " & DESTINATIONFOLDER, ErrorNumber, ErrorDescription, ErrorSource )
End If
 
session.Open sessionOptions
 
If Err.number = 0 Then
    ' Upload files
    Set transferOptions = GetTransferOptions()
    Set transferResult = session.PutFiles( File_From_s, DESTINATIONFOLDER, False, transferOptions )
 
    ' Throw on any error
    transferResult.Check
 
    If Err.number  > 0 Then
       Transfer_Succeeded_b = False
       ErrorNumber = Err.number
       ErrorDescription = Err.Description
       ErrorSource = Err.Source
       Err.Clear
       Call LogError( "Problem Transferring " & File_From_s & " to " & DESTINATIONFOLDER, ErrorNumber, ErrorDescription, ErrorSource )
       Call SendErrorMessage( "Problem Transferring " & File_From_s & " to " & DESTINATIONFOLDER, ErrorNumber, ErrorDescription, ErrorSource )
    End If
 
    ' Returns false      
    Result_x = transferResult.IsSuccess()
 
    ' Returns the name of the file that attempted to send, even though it didn't succeed.
    For Each transfer In transferResult.Transfers
        Dim FileName_s
        FileName_s = transfer.FileName
        LogStatus( "Upload of " & transfer.FileName & " succeeded" )
    Next
Else
    Transfer_Succeeded_b = False
    ErrorNumber = Err.number
    ErrorDescription = Err.Description
    ErrorSource = Err.Source
    Err.Clear
    Call LogError( "Problem Opening Session for " & File_From_s & " to " & DESTINATIONFOLDER, ErrorNumber, ErrorDescription, ErrorSource )
    Call SendErrorMessage( "Problem Opening Session for " & File_From_s & " to " & DESTINATIONFOLDER, ErrorNumber, ErrorDescription, ErrorSource )
End If
 
' Disconnect, clean up
session.Dispose
 
' ...
' ...
 
' Earlier in the script, this function is defined
' No errors, and confirmed that the CONSTANTs are defined'
Function GetTransferOptions
    Dim TransferOptions_obj
 
    Set TransferOptions_obj = WScript.CreateObject( "WinSCP.TransferOptions" )
    TransferOptions_obj.TransferMode = TransferMode_Ascii
    TransferOptions_obj.OverwriteMode = OverwriteMode_Overwrite
 
    Result_x = TransferMode_Ascii
    Result_x = OverwriteMode_Overwrite
 
    Result_x = TransferOptions_obj.TransferMode
    Result_x = TransferOptions_obj.OverwriteMode
 
    If Err.number  > 0 Then
        Transfer_Succeeded_b = False
        ErrorNumber = Err.number
        ErrorDescription = Err.Description
        ErrorSource = Err.Source
        Err.Clear
    End If
 
    Set GetTransferOptions = TransferOptions_obj
End Function

Reply with quote

Advertisement

Dan Curious
Donor
Joined:
Posts:
44
Location:
NY

Yep, that was definitely a problem, thanks.

Even with the logic errors, the transfer still gets attempted and fails. Now that the error check is corrected, it still fails.

So I need to set up the standard logs, to see what's happening from Winscp's vantage point.

I think that's covered here https://winscp.net/eng/docs/logging , but there were some other forum posts about it, so I'll read those first.

Reply with quote

Dan Curious
Donor
Joined:
Posts:
44
Location:
NY

Didn't set up the logs yet, but the error description from the module was revealing enough. The source filename was spelt wrong.

Now there's an odd error about a duplicate filename, even though there are no files in the destination folder. It almost looks like the destination folder is being interpreted as a file name rather than a folder name. But I don't know that for a fact, yet.
Cannot overwrite remote file '/InFolder'.$$

Press 'Delete' to delete the file and create new one instead of overwriting it.$$
General failure (server should provide error description).
Error code: 4
Error message from server: MailboxSystemProvider.openFile(S,UI32,SFA) Invalid handle - Duplicate file and dir path

Common reasons for the Error code 4 are:
- Renaming a file to a name of already existing file.
- Creating a directory that already exists.
- Moving a remote file to a different filesystem (HDD).
- Uploading a file to a full filesystem (HDD).
- Exceeding a user disk quota.

Reply with quote

Advertisement

Dan Curious
Donor
Joined:
Posts:
44
Location:
NY

Got it. PutFiles requires a destination PATH - meaning the name of the files that are being sent - and not just a destination folder.

I'm getting one of those 'but error occurred while setting the permissions...' error, but that setting is simple.

I think we're all set, thanks.

Reply with quote

Dan Curious
Donor
Joined:
Posts:
44
Location:
NY

To anyone with similar challenges in the future, specifically related to the Transfer options, make use of the AddRawSettings method, of the TransferOptions class. I used it with PreserveTimeDirs and IgnorePermErrors (setting them to 1), and it worked like a charm.

https://winscp.net/eng/docs/rawtransfersettings

Vbscript
TransferOptions_obj.AddRawSettings "PreserveTimeDirs", 1
TransferOptions_obj.AddRawSettings "IgnorePermErrors", 1

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,440
Location:
Prague, Czechia

Dan Curious wrote:

Got it. PutFiles requires a destination PATH - meaning the name of the files that are being sent - and not just a destination folder.
Destination folder is enough, but it must end with a slash.
See https://winscp.net/eng/docs/library_session_putfiles#remotepath:
Full path to upload the file to. When uploading multiple files, the filename in the path should be replaced with operation mask or omitted (path ends with slash).

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,440
Location:
Prague, Czechia

Dan Curious wrote:

To anyone with similar challenges in the future, specifically related to the Transfer options, make use of the AddRawSettings method, of the TransferOptions class. I used it with PreserveTimeDirs and IgnorePermErrors (setting them to 1), and it worked like a charm.
Setting PreserveTimeDirs to 1 cannot help in this case. The IgnorePermErrors can work as a workaround. But the right way is to set the TransferOptions.PreserveTimestamp to False:
https://winscp.net/eng/docs/message_preserve_time_perm#library

Reply with quote

Advertisement

Dan Curious
Donor

I thought I had tried with a slash in front, but there was still an error. I guess falsely concluded that the slash was the problem.

Ok, now that everything else is solid, I'll try with the slash, and then refactor sections into functions whenever practical.

Reply with quote

Dan Curious
Donor
Joined:
Posts:
44
Location:
NY

Ok, I reproduced the error with PutFiles(). It says that it can't overwrite remote file, and refers to the folder without the slash (even though it was supplied the destination folder with the slash), thus:
Cannot overwrite remote file, '/destinationfolder'.$$
That's the same error I received earlier, when appending a slash. So, at least right now, I have to use the PutFileToDirectory function. That's ok, since we're uploading one file at a time anyway.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,440
Location:
Prague, Czechia

The PutFileToDirectory(localPath, remotePath) basically does (a C# example, VBS would be slightly different):
PutFiles(localPath, RemotePath.AddDirectorySeparator(remotePath))
Nothing fancy. So if PutFileToDirectory works, the PutFiles with the remote path ending with a slash must work too.

Reply with quote

Dan Curious
Donor
Joined:
Posts:
44
Location:
NY

I'll take your word for it, and will assume I'm doing something wrong. For now, in order to move the project forward, we have to use PutFileToDirectory().

If we need to transfer multiple files to a server at some point, we'll revisit this.

T & R,

Reply with quote

Advertisement

Dan Curious
Donor
Joined:
Posts:
44
Location:
NY

Resolution: PutFileToDirectory is working fine, except that the return code is less convenient than PutFiles().

We found the problem with PutFiles - We needed to escape the slashes in the destination path, as in \\root\\filepath.dat.

Everything's good, thanks Martin. I'll get another donation out, during the summer.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,440
Location:
Prague, Czechia

Thanks for your feedback.

Regarding the slashes: That cannot be any different in PutFileToDirectory. Though, you should use forward slashes for remote paths, not backslashes.

Regarding what the methods return (I assume that's what you mean by "return code"): They return the same information basically. Except that PutFileToDirectory throws an exception on errors, while PutFiles does not.

Reply with quote

Advertisement

You can post new topics in this forum