lundi 30 mars 2015

How can I connect on my own PC to a local FileZilla FTP server for testings?

I downloaded the FileZilla Server and installed it.


Then I use in FileZilla as address: 127.0.0.1 port: 14147 and admin user name: admin


And it connected fine.

But now I want to connect to the server upload download and delete files using C#.


This is my code. This code was working fine when I used my online FTP server at ipage.com


But now I want to use it with the FileZilla.



string fff = "";
public string[] GetFileList()
{
string[] downloadFiles;
StringBuilder result = new StringBuilder();
WebResponse response = null;
StreamReader reader = null;
try
{
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + f.Host + "/"));
fff = "ftp://" + f.Host + "/";
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(f.Username, f.Password);
reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
reqFTP.Proxy = null;
reqFTP.KeepAlive = false;
reqFTP.UsePassive = false;
response = reqFTP.GetResponse();
reader = new StreamReader(response.GetResponseStream());
string line = reader.ReadLine();
while (line != null)
{
result.Append(line);
result.Append("\n");
line = reader.ReadLine();
}
result.Remove(result.ToString().LastIndexOf('\n'), 1);
return result.ToString().Split('\n');
}
catch (Exception ex)
{
if (reader != null)
{
reader.Close();
}
if (response != null)
{
response.Close();
}
downloadFiles = null;
return downloadFiles;
}
}


In fff I see ftp://127.0.0.1/ and f.Username is empty "" and f.Password is admin


Then I make continue and I'm getting exception:



The remote server returned an error: (501) Syntax error in parameters or arguments

System.Net.WebException was caught
HResult=-2146233079
Message=The remote server returned an error: (501) Syntax error in parameters or arguments.
Source=System
StackTrace:
at System.Net.FtpWebRequest.CheckError()
at System.Net.FtpWebRequest.SyncRequestCallback(Object obj)
at System.IO.Stream.Close()
at System.Net.ConnectionPool.Destroy(PooledStream pooledStream)
at System.Net.ConnectionPool.PutConnection(PooledStream pooledStream, Object owningObject, Int32 creationTimeout, Boolean canReuse)
at System.Net.FtpWebRequest.FinishRequestStage(RequestStage stage)
at System.Net.FtpWebRequest.GetResponse()
at FTP_ProgressBar.FtpProgress.GetFileList() in c:\ftp_progressbar\FTP_ProgressBar\FtpProgress.cs:line 342
InnerException:


Line 342 is:



response = reqFTP.GetResponse();


What I want is to demo FTP server so I can check my C# program on it.


Aucun commentaire:

Enregistrer un commentaire