[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Use FTP to Copy a file to Another Folder

Posted on 2013-11-27
8
Medium Priority
?
382 Views
Last Modified: 2013-11-28
I am attempting to copy a tab delimited text file to an FTP folder.

This is the example I am using: http://msdn.microsoft.com/en-us/library/ms229715(v=vs.110).aspx

// Copy the contents of the file to the request stream.
            StreamReader sourceStream = new StreamReader("Changes.txt");
            byte [] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
            sourceStream.Close();

error: The name Encoding does not exist in the current context.

I am not sure that  byte [] fileContents  applies to a tab delimited file.

This is the structure of Changes.txt:

     NameChangeDate           Market  OldName NewName
     2009-04-15 00:00:00.000      NASDAQ      SGIC      SGICQ
     2009-04-16 00:00:00.000      AMEX      ABH          ABWTQ
     2009-04-16 00:00:00.000      NYSE      GGP          GGWPQ
     2009-04-17 00:00:00.000      NASDAQ      XTLB      XTLBY
     2009-04-20 00:00:00.000      NASDAQ      ATTC      ATTCE

What is the correct syntax for reading the file contents?

Thanks
0
Comment
Question by:Dovberman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 9

Accepted Solution

by:
oheil earned 2000 total points
ID: 39680613
I think you have just forgot
using System.Text;

Open in new window

in your code.

Oli
0
 

Author Comment

by:Dovberman
ID: 39680771
Yes, That was simple. Thanks.

The example describes how to copy from one FTP folder to another.

I need to copy the file from my local machine folder to the FTP folder.

I know how to create the local filestream.

What do I need to change in the upload statement?

Or is this the subject of a new question?

Thanks
0
 

Author Closing Comment

by:Dovberman
ID: 39680939
Thank you.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:oheil
ID: 39680943
You are welcome.
0
 
LVL 9

Expert Comment

by:oheil
ID: 39680954
Odd: I posted some code for the upload, but it is not in the thread... maybe I didnt hit the Submit button? But I think it is clear from your own example which you linked above.

Have a good time,

Oli
0
 

Author Comment

by:Dovberman
ID: 39681245
Would you mind posting the upload code again?

Thanks
0
 
LVL 9

Expert Comment

by:oheil
ID: 39682973
Sure. I posted (or not):

Its not subject to a new question.

From your example above it would be something like:

           using System.Net;



           // Get the object used to communicate with the server.
            FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://your.server.com/some/path/your_file.txt");
            request.Method = WebRequestMethods.Ftp.UploadFile;

            // This example assumes the FTP site uses anonymous logon.
            request.Credentials = new NetworkCredential ("anonymous","janeDoe@contoso.com");

            request.ContentLength = fileContents.Length;
            Stream requestStream = request.GetRequestStream();
            requestStream.Write(fileContents, 0, fileContents.Length);
            requestStream.Close();

            FtpWebResponse response = (FtpWebResponse)request.GetResponse();
    
            Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);
    
            response.Close();

Open in new window


The line
request.Credentials = new NetworkCredential ("anonymous","janeDoe@contoso.com");
must be changed to your credentials.
Syntax is: NetworkCredential( String user, String password);

If everything is good, it should create the file "your_file.txt" on the server "your.server.com" in the directory "some/path/".

Oli
0
 

Author Comment

by:Dovberman
ID: 39684006
Thank you. This is how it worked for me.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question