Click here to Skip to main content
11,577,258 members (60,996 online)
Rate this: bad
good
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 3:57am
Comments
Zoltán Zörgő at 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 at 2-Apr-13 11:00am
   
The OP's tag is FTP, which is a better idea :-)
—SA
Ankit Kul at 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ő at 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 at 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 at 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 at 2-Apr-13 14:33pm
   
Anyway, try harder :-)
Please see my update to my answer, after [EDIT].
—SA
Ankit Kul at 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 at 2-Apr-13 14:43pm
   
OK, does it work?..
—SA
Ankit Kul at 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
Sergey Alexandrovich Kryukov at 2-Apr-13 16:37pm
   
Not clear. What's the difference between the two? you cannot make a different file names?
—SA
Sergey Alexandrovich Kryukov at 2-Apr-13 16:40pm
   
Please see another update, after [EDIT #2].
—SA
Ankit Kul at 2-Apr-13 17:45pm
   
thanks ,but the above code solved my issue.
Sergey Alexandrovich Kryukov at 2-Apr-13 17:57pm
   
Well, will you accept the answer formally (green button)?
—SA
Maciej Los at 2-Apr-13 15:25pm
   
Short and to the point. +5!
I'll refer to your past answers...
Sergey Alexandrovich Kryukov at 2-Apr-13 16:37pm
   
Thank you, Maciej.
OP still has some weird problem...
—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
0 DamithSL 155
1 Afzaal Ahmad Zeeshan 125
2 OriginalGriff 115
3 Richard MacCutchan 100
4 Abhinav S 90
0 OriginalGriff 820
1 Sergey Alexandrovich Kryukov 676
2 Abhinav S 528
3 F-ES Sitecore 420
4 Suvendu Shekhar Giri 375


Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 2 Apr 2013
Copyright © CodeProject, 1999-2015
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