Topic "Working session.CreateDirectory example for VB.NET/VBA"

Author Message
thom321
[View user's profile]

Joined: 2014-10-28
Posts: 5
I have been trying to find a detailed example in either VB.NET or VBA for how to use .CreateDirectory since I can't get it to work.

I can get the Upload example to work fine.

So best case scenario, I would like an example that includes:
Which object to declare?
My assumption is RemoteDirectoryInfo but I really don't know
e.g.
Dim newDir as RemoteDirectoryInfo

How to exactly specify the path. My relative path "/test/" works fine when uploading a file but fails when using
Set newDir = mySession.CreateDirectory("/test2/")

How can I implement error checking and confirmation similar to how it is done for uploads?
Uploads can use code like:
' Throw on any error
transferResult.Check

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

I would like to be able to do the same for checking if the directory was created before resuming the rest of the procedure.

Thankful for any help.

Regards,
Tom
Advertisements
thom321
[View user's profile]

Joined: 2014-10-28
Posts: 5
As an FYI, simply doing:

session.CreateDirectory(path) e.g.

Dim mySession as Session
mySession.CreateDirectory("/test2/")

does not work either. Returns an error saying the folder could not be created.

thom321 wrote:
I have been trying to find a detailed example in either VB.NET or VBA for how to use .CreateDirectory since I can't get it to work.

I can get the Upload example to work fine.

So best case scenario, I would like an example that includes:
Which object to declare?
My assumption is RemoteDirectoryInfo but I really don't know
e.g.
Dim newDir as RemoteDirectoryInfo

How to exactly specify the path. My relative path "/test/" works fine when uploading a file but fails when using
Set newDir = mySession.CreateDirectory("/test2/")

How can I implement error checking and confirmation similar to how it is done for uploads?
Uploads can use code like:
' Throw on any error
transferResult.Check

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

I would like to be able to do the same for checking if the directory was created before resuming the rest of the procedure.

Thankful for any help.

Regards,
Tom
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25025
Location: Prague, Czechia
thom321 wrote:
How to exactly specify the path. My relative path "/test/" works fine when uploading a file but fails when using
Set newDir = mySession.CreateDirectory("/test2/")

Try just "/test" (no trailing slash).

(Btw, the "/test/" seems like an absolute path to me).

Quote:
How can I implement error checking and confirmation similar to how it is done for uploads?

The Session.CreateDirectory throw an exception on any error.
See https://winscp.net/eng/docs/library_session_createdirectory#exceptions
thom321
[View user's profile]

Joined: 2014-10-28
Posts: 5
Update: Figured out the issue. I had misunderstood how to reference the remote path. Now when I use
mySession.CreateDirectory("example.com/test2")

it works fine.

Btw, thanks for a cool piece of software with a working API

---
Thanks for your response.

I did try using

mySession.CreateDirectory("/test2") i.e. without the slash as well.

I feel like I am missing something really simple here so maybe a specific example would be easier.
Let's say my domain is
"www.example.com"

and I want to add the directory
"test2"

The code:

Dim mySession As New Session
Dim mySessionOptions As New SessionOptions

With mySessionOptions
.Protocol = Protocol_Ftp
.HostName = "example.com"
.UserName = "user"
.Password = "password"

End With

mySession.Open mySessionOptions

'Until this point the code works fine.

mySession.CreateDirectory ("/test2") 'DOES NOT WORK
mySession.CreateDirectory ("/test2/") 'DOES NOT WORK
mySession.CreateDirectory ("test2") 'DOES NOT WORK
mySession.CreateDirectory ("test2/") 'DOES NOT WORK



What code do I need to add to create the directory "test2" for domain "www.example.com"?




prikryl wrote:
thom321 wrote:
How to exactly specify the path. My relative path "/test/" works fine when uploading a file but fails when using
Set newDir = mySession.CreateDirectory("/test2/")

Try just "/test" (no trailing slash).

(Btw, the "/test/" seems like an absolute path to me).

Quote:
How can I implement error checking and confirmation similar to how it is done for uploads?

The Session.CreateDirectory throw an exception on any error.
See https://winscp.net/eng/docs/library_session_createdirectory#exceptions
Advertisements

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!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License