Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET Remote
Hello,
 
i have to copy files from ftp to remote desktop computer.
 
try
{
    File.Copy("ftp://IP Address:Port/My Folder/MyFile.dll", @"Remote IP Address\My Location");
}
catch(Exception ex)
{
    Console.Write(ex.Message);
}
 
But, i could not do this. I think the possible reasons might be:
(1)the ftp and remote desktop requires password (credentials).
(2)i am trying to copy file to a folder who is not shared.
(3)Any other issue........
 

if(1), then how can handle credentials in my code?
if(2), then how can copy files to a folder who is not shared?
if(3), tell me the actual reason and how to handle it?
 
thanks,
Posted 4-Jan-12 4:13am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Take a look at this article on MSDN
How to: Upload Files with FTP[^].
 
It outlines how to use credentials and such with a very nice clean code sample.
  Permalink  
v2
Comments
Espen Harlinn at 4-Jan-12 11:27am
   
Good link :)
SAKryukov at 4-Jan-12 12:33pm
   
Yes, but the only problem is: OP wants to download, not upload. I provided a solution, please see.
--SA
Espen Harlinn at 4-Jan-12 15:56pm
   
Yes, I noticed that answer nearly a year ago :)
Wonde Tadesse at 4-Jan-12 17:42pm
   
5+
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

File copy does not work with FTP. I provided a complete solution in my past answer, please see: FTP: Download Files[^].

—SA
  Permalink  
Comments
Espen Harlinn at 4-Jan-12 15:55pm
   
5'ed!
SAKryukov at 4-Jan-12 18:40pm
   
Thank you, Espen.
--SA
Wonde Tadesse at 4-Jan-12 17:42pm
   
5+
SAKryukov at 4-Jan-12 18:40pm
   
Thank you, Wonde.
--SA
Harish Kumar Bansal at 11-Jan-12 5:14am
   
Thanks, i have successfully copy file from FTP. Now i have to Paste this file to Remote Desktop PC which does not have any shared folder. Is it possible?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

File.copy automatically doesn't handle FTP protocol. You need to download the file using FTP related libraries. You can use System.Net.FtpWebRequest
 
You can download it to a temp location or directly to the network path(UNC). Network folder need not to be shared if the process identity have admin access to the target machine. In that case the location can be accessed by \\machineName\C$\targetFolder . Change the drive letter C to whatever drive you are using.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

any one must not write code without testing because visiters have no time.so i request to all solution giver at codeproject to add only right code
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

You have to use FtpWebRequest & FtpWebResponse and after that you have to get response.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://path/test.htm");
            request.Method = WebRequestMethods.Ftp.UploadFile;
            // This example assumes the FTP site uses anonymous logon.
            request.Credentials = new NetworkCredential ("anonymous","abc@xyz.com");            
            
            StreamReader sourceStream = new StreamReader("testfile.txt");
            byte [] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
            sourceStream.Close();
            request.ContentLength = fileContents.Length;
 
            Stream requestStream = request.GetRequestStream();
            requestStream.Write(fileContents, 0, fileContents.Length);
            requestStream.Close();
            FtpWebResponse response = (FtpWebResponse)request.GetResponse();
    
            response.Close();
  Permalink  
v3

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 886
1 OriginalGriff 390
2 CPallini 255
3 Volynsky Alex 205
4 Richard Deeming 175
0 OriginalGriff 5,540
1 Sergey Alexandrovich Kryukov 4,668
2 CPallini 4,540
3 George Jonsson 3,102
4 Gihan Liyanage 2,445


Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 29 Sep 2012
Copyright © CodeProject, 1999-2014
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