Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

thom321

Re: Working session.CreateDirectory example for VB.NET/VBA

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"?




martin 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).

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
martin

Re: Working session.CreateDirectory example for VB.NET/VBA

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).

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

Re: Working session.CreateDirectory example for VB.NET/VBA

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
thom321

Working session.CreateDirectory example for VB.NET/VBA

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