Click here to Skip to main content
15,879,490 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How can I transfer files from one server http://abc.com to another server http://xyz.com

I do have the passwords of both servers i.e. http://abc.com [source server] and destination server.
Posted
Comments
Zoltán Zörgő 2-Apr-13 10:00am    
You want file transfer with http? Not a good idea. Is there no other service opened or possible to be opened between them - in no direction?
Sergey Alexandrovich Kryukov 2-Apr-13 11:00am    
The OP's tag is FTP, which is a better idea :-)
—SA
Asp_Learner 2-Apr-13 10:06am    
we have full access for both the servers. we can do anything ,so please suggest whatever you want
Zoltán Zörgő 2-Apr-13 13:10pm    
Than the question is (it is a valid question also if you choose tfp) what is the relation of these servers in the infrastructure? Are they on the same LAN/CAN or are they remote (not psychically, but from routed service point of view), and the file transfer will go trough the internet? What is the purpose of this transfer? If they are remote to each other, ftp can be a good choice, but you will still need to consider security and firewalls. If they are on the same LAN/CAN, you have better options than ftp.

As FTP is tagged, which is quite an acceptable approach to the file transfer, all you need is to have FTP server on one of the hosts, and you can develop a client part of FTP transfer using the class System.Net.FtpWebRequest:
http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.aspx[^].

(Would you need to develop the server-side of FTP as well? I don't think you will need it, but you can find an appropriate pure .NET library on CodeProject and elsewhere. FTP is the application-level protocol over TCP, which is fully and natively implemented in .NET FCL, so this is not a problem, too.)
[EDIT #1]

Probably you did not find how to copy a file, because you did not learn all the request types:
http://msdn.microsoft.com/en-us/library/system.net.webrequestmethods.ftp.aspx[^].

To copy a file, you use either the method DownloadFile or the UploadFile.

Also, you should not forget that the FTP server can configure different access privileges for different users, so you have to take care about proper configuration.

[EDIT #2]

You can find the upload code sample here: http://msdn.microsoft.com/en-us/library/ms229715.aspx[^].

—SA
 
Share this answer
 
v4
Comments
Asp_Learner 2-Apr-13 14:11pm    
thanks for help ,I am able to create a file on another server ,but I cant copy a file from source server to destination server.
Sergey Alexandrovich Kryukov 2-Apr-13 14:29pm    
Yes, you can. Where is the server part and the client part: on source or destination? In other words, are you uploading or downloading?
No matter, you can do it all.
—SA
Sergey Alexandrovich Kryukov 2-Apr-13 14:33pm    
Anyway, try harder :-)
Please see my update to my answer, after [EDIT].
—SA
Asp_Learner 2-Apr-13 14:41pm    
string CompleteDPath = "";
CompleteDPath = "ftp://1234.1234.12.13/";


string UName = "";
string PWD = "";
UName = "Administrator";
PWD = "12345";


WebRequest reqObj = WebRequest.Create(CompleteDPath + "abc.jpg");
reqObj.Method = WebRequestMethods.Ftp.UploadFile;
reqObj.Credentials = new NetworkCredential(UName, PWD);
FileStream streamObj = System.IO.File.OpenRead(physical path + "test.jpg");
byte[] buffer = new byte[streamObj.Length + 1];
streamObj.Read(buffer, 0, buffer.Length);
streamObj.Close();
streamObj = null;
reqObj.GetRequestStream().Write(buffer, 0, buffer.Length);
reqObj = null;
Sergey Alexandrovich Kryukov 2-Apr-13 14:43pm    
OK, does it work?..
—SA
string CompleteDPath = "";
            CompleteDPath = "ftp://1234.1234.12.13/";


            string UName = "";
            string PWD = "";
            UName = "Administrator";
            PWD = "12345";


            WebRequest reqObj = WebRequest.Create(CompleteDPath + "abc.jpg");
            reqObj.Method = WebRequestMethods.Ftp.UploadFile;
            reqObj.Credentials = new NetworkCredential(UName, PWD);
            FileStream streamObj = System.IO.File.OpenRead(physical path + "test.jpg");
            byte[] buffer = new byte[streamObj.Length + 1];
            streamObj.Read(buffer, 0, buffer.Length);
            streamObj.Close();
            streamObj = null;
            reqObj.GetRequestStream().Write(buffer, 0, buffer.Length);
            reqObj = null;
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900