lundi 30 mars 2015

When trying to upload a file to my own ftp server i created using filezilla i'm getting The requested URI is invalid for this FTP command why?

This my ftp upload method:



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;
}
}


For the test fff contain: ftp://127.0.0.1/ And in the filezilla i see in the log:



(000006)30/03/2015 21:59:24 - (not logged in) (127.0.0.1)> Connected on port 21, sending welcome message...
(000006)30/03/2015 21:59:24 - (not logged in) (127.0.0.1)> 220-FileZilla Server version 0.9.50 beta
(000006)30/03/2015 21:59:24 - (not logged in) (127.0.0.1)> 220-written by Tim Kosse (tim.kosse@filezilla-project.org)
(000006)30/03/2015 21:59:24 - (not logged in) (127.0.0.1)> 220 Please visit http://ift.tt/13OgtXY
(000006)30/03/2015 21:59:24 - (not logged in) (127.0.0.1)> disconnected.


But the file is not uploaded instead i'm getting exception message in my program:


The requested URI is invalid for this FTP command



System.Net.WebException was caught
HResult=-2146233079
Message=The requested URI is invalid for this FTP command.
Source=System
StackTrace:
at System.Net.FtpWebRequest.CheckError()
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();


In fileZilla i created a user i have a password and user name i added a directory and gave a permission to write delete read for files and directories.


Aucun commentaire:

Enregistrer un commentaire