Error in replication in background agent

I have an agent on One server(S1) and i want to use that agent to create replicas of database on another server (S2)i used the code

Set ArchDBAlt = ArchiveDB.CreateReplica(ArkServer2Alt, ArchivePath & NewFileName$)

If i use IP address of the replica server (S2) in place of ‘ArkServer2Alt’ it works but it doesn’t work if i use server name.

I tried creating conn. document. , Creating server doc of S2 on S1, Checked Host file

but nothing works.

What are the steps i need to do to set up replication using backgorund script

Syed