Click here to Skip to main content
15,883,883 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
List<string> Files = new List<string>();

            FtpWebRequest request = (FtpWebRequest)WebRequest.Create(new Uri(host + "/" + remoteFile));
            request.Method = WebRequestMethods.Ftp.ListDirectory;

            request.Credentials = new NetworkCredential("Adminstrator", "password@123"); 

            request.UseBinary = false;
            request.UsePassive = true;

            FtpWebResponse response = (FtpWebResponse)request.GetResponse();

            Stream responseStream = response.GetResponseStream(); //ERROR IS HERE
            StreamReader reader = new StreamReader(localFile);
            string CurrentLine = reader.ReadLine();
            while (!string.IsNullOrEmpty(CurrentLine))
            {
                Files.Add(CurrentLine);
                CurrentLine = reader.ReadLine();
            }
            reader.Close();
            response.Close();


What I have tried:

//using (System.Net.WebClient client = new System.Net.WebClient())
//{
// client.Credentials = new System.Net.NetworkCredential("Adminstrator", "password@123");
// client.UploadFile(host + "/" + new FileInfo(remoteFile).Name, "STOR", localFile);
//}.


The remote server returned an error: (530) Not logged in.
Posted
Updated 21-Dec-17 22:37pm
Comments
Jochen Arndt 1-Apr-16 5:40am    
You might have passed wrong credentials.
Maybe the user name should be "Administrator" instead of "Adminstrator"?

You might also check the FtpWebResponse status after calling GetResponse().
Thomas Nielsen - getCore 1-Apr-16 5:55am    
Error is not necessarily where you write //ERROR IS HERE,
it's just that it doesn't actually send the request until you call there, so all you know is that it is between instantiation of request and call to GetResponse()

Have a look at this Simple C# FTP class, it appears to do what you want and would propably be more efficient to copy for you.

Simple C# FTP Class[^]
 
Share this answer
 
In my case, i have cross checked the server and credentials with Filezilla utility first and checked the path of the directory to which i have to upload files. whatever the access the user get after logged into filezilla, we just have to use it like.. ( /dir/dir1/dir2 ) after IP followed by slash.

ex:

ftp://111.111.11.11/(directory path looks like into filezilla)
ftp://111.11.11.111/dir1/dir2/dir3

also i have updated
request.EnableSsl = false;


and it is working for me.
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900