initial port from the c# copy