mburk1968
asked on
ftpwebrequest Help C#
I can compile this code and run it without issue in Visual Studio. However where is it saving the file that it downloads if indeed it is actually downloading a file?
using System;
using System.IO;
using System.Net;
using System.Text;
namespace Examples.System.Net
{
public class WebRequestGetExample
{
public static void Main()
{
// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://mysite.net/site/wwwroot/ftp/Export.csv");
request.Method = WebRequestMethods.Ftp.DownloadFile;
// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential("Username\\$username", "password");
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
Console.WriteLine(reader.ReadToEnd());
Console.WriteLine("Download Complete, status {0}", response.StatusDescription);
reader.Close();
response.Close();
}
}
}
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Receiving 3 errors
Severity Code Description Project File Line Suppression State
Error CS1010 Newline in constant FTPConsoleApplication C:\Users\dell main\Documents\Visual Studio 2015\Projects\FTPConsoleAp plication\ FTPConsole Applicatio n\FTPConso leApplicat ion\Progra m.cs 26 Active
Severity Code Description Project File Line Suppression State
Error CS1003 Syntax error, ',' expected FTPConsoleApplication C:\Users\dell main\Documents\Visual Studio 2015\Projects\FTPConsoleAp plication\ FTPConsole Applicatio n\FTPConso leApplicat ion\Progra m.cs 26 Active
Severity Code Description Project File Line Suppression State
Error CS1026 ) expected FTPConsoleApplication C:\Users\dell main\Documents\Visual Studio 2015\Projects\FTPConsoleAp plication\ FTPConsole Applicatio n\FTPConso leApplicat ion\Progra m.cs 29 Active
Severity Code Description Project File Line Suppression State
Error CS1010 Newline in constant FTPConsoleApplication C:\Users\dell main\Documents\Visual Studio 2015\Projects\FTPConsoleAp
Severity Code Description Project File Line Suppression State
Error CS1003 Syntax error, ',' expected FTPConsoleApplication C:\Users\dell main\Documents\Visual Studio 2015\Projects\FTPConsoleAp
Severity Code Description Project File Line Suppression State
Error CS1026 ) expected FTPConsoleApplication C:\Users\dell main\Documents\Visual Studio 2015\Projects\FTPConsoleAp
Are these errors you are getting being returned from the reader on this line of code, Console.WriteLine(reader.R eadToEnd() );? or other code?
What are on lines 26 - 30?
What are on lines 26 - 30?
ASKER
File.WriteAllText("c:\\tem p\\export. csv", "reader.ReadToEnd());
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
I cannot thank you both enough. I've been struggling with this. Awesome!
Not a problem, glad to help.
Open in new window