EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Detecting Whether Directory Exists Using SimpleSFTPClient

Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.
#3544
Posted: 08/14/2007 19:29:14
by Dan Hammari (Basic support level)
Joined: 06/27/2006
Posts: 11

Hello,

I am using the TElSimpleSFTPClient to upload files to an SFTP site. I would like to create a directory in which to place the files, but am having some trouble finding an elegant way to detect whether a directory already exists before I try and create it. Whereas ElSftpClient.OpenDirectory returns a boolean, ElSimpleSFTPClient.OpenDirectory does not. I could put a brute force try..except block around ElSimpleSFTPClient.MakeDirectory, but I'd prefer not to go that route. Could someone suggest a better way to detect whether a directory already exists so I don't attempt to create it when it's already there?

Thanks,
Dan
#3545
Posted: 08/15/2007 01:35:22
by Eugene Mayevski (EldoS Corp.)

Use RetrieveAttributes method to retrieve the attributes of the directory.


Sincerely yours
Eugene Mayevski
#3547
Posted: 08/15/2007 11:50:07
by Eugene Mayevski (EldoS Corp.)

I am sorry, the method is called RequestAttributes. I mix the verbs sometimes :(

When the directory doesn't exist, the exception is raised. The exception's ErrorCode property will be SSH_ERROR_EOF (Integer code 1).


Sincerely yours
Eugene Mayevski
#3548
Posted: 08/15/2007 11:52:00
by Dan Hammari (Basic support level)
Joined: 06/27/2006
Posts: 11

Hello,

I created a custom error procedure and linked it to the ElSimpleSFTPClient.OnError event. I then called the ElSimpleSFTPClient.RequestAttributes method in my code to see if the object would call the custom OnError procedure I had just created. For some reason, the ElSimpleSFTPClient object does not enter my custom procedure and insists on returning its own error messages.

I also noticed that even though my custom procedure which contained the ElSimpleSFTPClient.MakeDi­rectory method did not run, the ElSimpleSFTPClient.UploadFile method seemed to create the directory for me. Does the ElSimpleSFTPClient.UploadFile method have instructions inside it to automatically create a directory if it is instructed to post a file in a folder that does not yet exist? If so, then I can ignore detecting whether a directory exists altogether and simply declare a non-existent path as I post files.

Thanks,
Dan
#3550
Posted: 08/15/2007 13:08:40
by Eugene Mayevski (EldoS Corp.)

There are errors and errors. Some SFTP errors signal an exceptional situation and are reported via OnError event. Some errors are just non-OK results from the server when you call some method (such as No Permissions or No Such File errors). This kind of errors is reported using exceptions.

What ElSimpleSftpClient does is (in pseudocode)

ErrCode = InternalElSftpClient.RequestAttributes(...);
if (ErrCode != OK)
throw ESFTPError(ErrCode, MessageFromCode(ErrCode));


Regarding UploadFile - Yes, UploadStream and UploadFile methods attempt to create the remote folder.


Sincerely yours
Eugene Mayevski
Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.

Reply

Statistics

Topic viewed 2241 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!