Topic "VBA using session.MoveFile"

Author Message
[View user's profile]

Joined: 2014-01-30
Posts: 1
Location: California
I am using VBA within Access to upload a file to SFtp which works fine.

I need to rename the file on the SFtp site is that possible using the VBA methods?

I keep getting "Object required" below is the code:

Private Sub Upload(ByRef mySession As Session)

' Setup session options
Dim mySessionOptions As New SessionOptions
With mySessionOptions
.Protocol = Protocol_Sftp
.HostName = ""
.UserName = "xxxxxxx"
.Password = "xxxxxxxx"
.SshHostKey = "ssh-dss 1024 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
End With
' Get file name
Dim strFile As String
strFile = Dir("\\\Corp\IT\scripts\Credit\SendTest\*.u01")

' Connect
mySession.DisableVersioncheck = True
mySession.Open mySessionOptions

' Upload files
Dim myTransferOptions As New TransferOptions
myTransferOptions.TransferMode = TransferMode_Binary

Dim transferResult As TransferOperationResult
Dim myMoveResult As SessionRemoteException
Set transferResult = mySession.PutFiles("\\\Corp\IT\scripts\Credit\SendTest\" & strFile & "", strFile, False, myTransferOptions)

'GET ERROR HERE***********************************************************
Set myMoveResult = mySession.MoveFile(strFile, "cz311660.r01")

' Throw on any error

' Display results
Dim intSuccess As Integer
Dim transfer As TransferEventArgs

For Each transfer In transferResult.Transfers
MsgBox "Upload of " & transfer.FileName & " succeeded!"
intSuccess = 1

If intSuccess <> 1 Then
Err.Raise 999, , "Failed to upload file!"
'MsgBox "File did not send properly."
End If

End Sub
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
On what line do you get the "Object required"?
Martin Prikryl


prikryl wrote:
On what line do you get the "Object required"?

I encountered the same Error : Object required : 'MoveFile(...'

Using WinSCP 5.5.6 , VBScripts "MovefileError.vbs". The scripts as below.
The Error occured at 'Line: 20'. The file was renamed from examplefile.txt to newexamplefile.txt successfully.

' Setup session options
Dim sessionOptions
Set sessionOptions = WScript.CreateObject("WinSCP.SessionOptions")
With sessionOptions
.Protocol = Protocol_Sftp
.HostName = ""
.UserName = "xxx"
.Password = "xxx"
.SshHostKeyFingerprint = "xxx"
End With
Dim session
Set session = WScript.CreateObject("WinSCP.Session")
' Connect
session.Open sessionOptions
Dim remotePath
remotePath = "/Usr/ftp4datalink/davis/examplefile.txt"
Dim newRemotePath
newRemotePath = "/Usr/ftp4datalink/davis/newexamplefile.txt"


' Disconnect, clean up
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
Both @egray and @David:
The Session.MoveFile does not have a return value.
Martin Prikryl

You can post new topics in this forum

Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!


About donations

$9   $19   $49   $99

About donations


WinSCP Privacy Policy

WinSCP License