We use perturbative QCD to calculate the cross sections sigma(L,T) for
the diffractive production of open charm (<c(c)over bar>) from longit
udinally and transversely polarised photons (or virtuality Q(2)) incid
ent at high energy (root s) on a proton target. We study both the Q(2)
and M-2 dependence of the cross sections, where hi is the invariant m
ass of the <c(c)over bar> pair. Surprisingly, the result for sigma(T),
as well as for sigma(L), is perturbatively stable. We estimate higher
-order corrections and find a sizeable enhancement of the cross sectio
ns. The cross sections depend on the square of the gluon density g(x,
K-2), and we show that the observation of open charm at the HERA elect
ron-proton collider can act as a sensitive probe of the gluon distribu
tion for x = (Q(2) + M-2)/s and scale K-2 = (m(c)(2) + < k(T)(2) >)(1
+ Q(2)/M-2) where the average quark transverse momentum squared < k(T)
(2) > similar to m(c)(2). As compared to diffractive J/psi production,
open charm has the advantage that it is independent of the non-pertur
bative ambiguities arising from the J/psi wave function. We estimate t
he fraction of diffractive events that arise from <c(c)over bar> produ
ction.