Jump to content
Mark Williams

FTP add virtual directory

Recommended Posts

Using IIS.  New to FTP.

 

Can anyone please give me a steer as to how to programmatically add and configure virtual FTP directories in IIS via Delphi?

Share this post


Link to post

I've never set these up, but isn't that something you would configure on ISS itself, and then refer to from Delphi?

Lots of security angles to consider

Share this post


Link to post
25 minutes ago, Lars Fosdal said:

I've never set these up, but isn't that something you would configure on ISS itself, and then refer to from Delphi?

Lots of security angles to consider

Yes it's pretty easy to set up via IIS, but the security angle is precisely why I don't wish to do it this way. I want to check the user's credentials against  database and then issue that user a one-off password for a single transaction and add a temporary ftp folder, which then gets removed as soon as the user has completed the transaction. There may be better ways of doing this. As I said I'm a FTP novice!

Share this post


Link to post

IIS FTP uses Windows accounts, so you need to set-up those from Delphi as well, can probably be scripted. 

 

The usual solution to your problem is to use a long random file name that disappears once the download is completed, but you need to watch the log to see when that happens.

 

The better solution is to you use a Delphi FTP server, like the ICS one I support, then you can control logins and directories yourself easily, using the ICS FTP Server sample you should have a working solution in a few hours, days faster than using WMI.  But it needs it's own IP address and port, will not help if you have to use IIS.  

 

There is no type library for the IIS management stuff, it's all WBEM based code.

 

Angus

 

Share this post


Link to post
28 minutes ago, Angus Robertson said:

The usual solution to your problem is to use a long random file name that disappears once the download is completed, but you need to watch the log to see when that happens.

Is it not possible to also password protect the folder? My intention is to maintain a record of the virtual folders in a database and require the user to signal continued use of the folder and as soon as there is a failure to do so the folder would be deleted.

 

37 minutes ago, Angus Robertson said:

The better solution is to you use a Delphi FTP server, like the ICS one I support, then you can control logins and directories yourself easily, using the ICS FTP Server sample you should have a working solution in a few hours, days faster than using WMI. 

Is this the Overbyte stuff? I will have a look.

 

Quote

But it needs it's own IP address and port, will not help if you have to use IIS.

So if I wanted to run IIS and ICS on the same server I would need a second static ip?

Share this post


Link to post

You can apply file permissions to Windows folders against Windows logins, but not password protect a folder. 

 

Yes, ICS is from Overbyte, there is an ICS forum.  You could run your FTP server on strange ports, but that is usually a nightmare with FTP and firewalls/routers.  Fortunately my hosted server has a /27 subnet, don't even use all of them.

 

Angus

 

Share this post


Link to post
6 hours ago, Angus Robertson said:

The better solution is to you use a Delphi FTP server, like the ICS one I support

Or the one in Indy (TIdFTPServer).

6 hours ago, Mark Williams said:

Is it not possible to also password protect the folder?

Not in FTP, no.  That is simply not how the FTP protocol works.  The client has to login up front at the beginning of the FTP session, and cannot re-login again afterwards without disconnecting first.

6 hours ago, Mark Williams said:

My intention is to maintain a record of the virtual folders in a database and require the user to signal continued use of the folder and as soon as there is a failure to do so the folder would be deleted.

Like Angus said, you will basically have to create your own FTP server that you have complete control over.  A pre-existing server, like IIS, is not really going to help you with this kind of task.  Statically defined virtual folders, yes.  But dynamically defined virtual folders, no.  Server components like the ones in ICS and Indy give you direct access to the client's commands, and virtual folders is really not that difficult to implement when you have direct access to the paths the client is trying to access.

 

I once wrote a virtual folder manager for Indy (I don't have it any more, though), it is just a matter of splitting a requested path into its individual parts and then walking the parts resolving each one to a physical folder as needed until you end up with a final physical path.

 

So, in your case, when the user starts the transaction, you create the virtual folder in your DB/whatever and make sure that folder is resolvable to a physical folder and is included in directory listings as needed.  When the transaction is done, delete the virtual folder from your DB/whatever.  If the client requests a path that includes a virtual folder that is no longer resolvable, a standard FTP 55x error response, like 550 or 553, will suffice to let the client know the path is no longer valid.

  • Like 1

Share this post


Link to post

@Remy LebeauThanks for the detailed response. Are there any problems running an Indy FTP server alongside IIS? Also, do you know of any good sample FTP server projects anywhere?

Share this post


Link to post

I have used Indy FTP server. You can start from Indy's demo code.

 

How about ICS? I have never used ICS.

 

On IIS server, you must close its own FTP server because it using port 21, and your own FTP server such as Indy TFP server will use it.

Or, your own FTP server can setup to using other port, and you will tell your user to ftp another port such as: FTP://your-server-IP:2121

Share this post


Link to post
On 3/2/2020 at 10:47 AM, Mark Williams said:

@Remy LebeauThanks for the detailed response. Are there any problems running an Indy FTP server alongside IIS?

As long as they are using separate IP/Ports, and any NAT proxy/router they are sitting behind has been configured properly for port forwarding, then there should be no problem.

On 3/2/2020 at 10:47 AM, Mark Williams said:

Also, do you know of any good sample FTP server projects anywhere?

No.

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×