Click here to Skip to main content
12,078,070 members (48,381 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET FTP
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 2-Apr-13 4:57am
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?
   
The OP's tag is FTP, which is a better idea :-)
—SA
Ankit Kul 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.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
v4
Comments
Ankit Kul 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.
   
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
   
Anyway, try harder :-)
Please see my update to my answer, after [EDIT].
—SA
Ankit Kul 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;
   
OK, does it work?..
—SA
Ankit Kul 2-Apr-13 16:13pm
   
it works ,but it creates a file named abc.jpg to the destination server ,but it cant copy the image test.jpg to the destination server
   
Not clear. What's the difference between the two? you cannot make a different file names?
—SA
   
Please see another update, after [EDIT #2].
—SA
Ankit Kul 2-Apr-13 17:45pm
   
thanks ,but the above code solved my issue.
   
Well, will you accept the answer formally (green button)?
—SA
Maciej Los 2-Apr-13 15:25pm
   
Short and to the point. +5!
I'll refer to your past answers...
   
Thank you, Maciej.
OP still has some weird problem...
—SA
Member 10240907 24-Jul-15 11:16am
   
Hi this code is working in local host but not working when i hosted .
Sergey Alexandrovich Kryukov 24-Jul-15 12:17pm
   
You have been running a local FTP server. Everything could be different: authentication, firewall settings...
First, use some available FTP client to replicate the file transfer you want. Your code should replicate all the settings.
—SA
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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;
  Permalink  
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160212.1 | Last Updated 2 Apr 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100