File Upload in WinSCP through vba

ashokkumar1234

New Member
Joined
Dec 21, 2017
Messages
1
I am trying to develop code for save the file in sftpcf (winscp) server but error in <code style="margin: 0px; padding: 1px 5px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: 13px; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; background-color: rgb(239, 240, 241); white-space: pre-wrap;">Session</code> and showing error as
user defined type not defined
I am not sure below code working or not and I copied the code from internet source.
any suggestion would be appreciated.


<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; white-space: inherit;">PrivateSub Upload(ByRef mySession As Session,ByRef wb1 As Workbook)'error line
Dim wb As Workbook
Set wb = Workbooks(wb1)
' Setup session options
Dim mySessionOptions AsNew SessionOptions
With mySessionOptions
.Protocol = Protocol_SFTP
.HostName ="103.231.8.66"
.UserName ="sftpcf"
.Password ="5|\/35TaR230@%"
.SshHostKeyFingerprint ="ssh-ed25519 256 df:94:44:56:1b:c2:75:8b:b4:58:3a:e2:ef:2e:0d:78"
EndWith

' Connect
mySession
.Open mySessionOptions

' Upload files
Dim myTransferOptions AsNew TransferOptions
myTransferOptions
.TransferMode = TransferMode_Binary

Dim transferResult As TransferOperationResult
Set transferResult = mySession.PutFiles(wb1,"/home/sftpcf/",False, myTransferOptions)

' Throw on any error
transferResult
.Check

' Display results
Dim transfer As TransferEventArgs
ForEach transfer In transferResult.Transfers
MsgBox
"Upload of "& transfer.FileName &" succeeded"
Next

EndSub</code>
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top