C# .NET - The remote server returned an error: (550) File unavailable (e.g., file not found, no access).

Asked By Erik Little on 06-Nov-06 11:08 AM

They say that Dentist have a high rate of sucide; however, i think that developers could fall into that catagory also..

I am using the FtpWebRequest and FtpWebResponse to retrieve directory and file info from an ftp server... Everthing works fine for the first go to the server; however , on the second go i get an 505 not found or in use..   I know that the files are their becuae i am looking at them in IE. Not only that i can get the files that are not found in the first request by simple makeing them the first request..

Here is what i am doing..

Pass in root to get its subDirectorys

Then i would like to loop and get the subDirectorys ; subDirectorys

Can someone tell me where i am going wrong here?

Below is the only code that hits the network.. How can i force close, or what can i do to work around?

thanks

erik

public static List<FileDirInfo> GetFileAndDirNames(string remotePathUri)

{

if (remotePathUri.EndsWith("/"))

remotePathUri = remotePathUri.Remove(remotePathUri.Length - 1);

WebRequest ftp = BuildFtpWebRequest(new Uri(remotePathUri));

ftp.Method = WebRequestMethods.Ftp.ListDirectoryDetails;

//

List<FileDirInfo> result = new List<FileDirInfo>();

//

try

{//

using (WebResponse response = (WebResponse)ftp.GetResponse())

{//

using (StreamReader reader = new StreamReader(response.GetResponseStream()))

{//

string line = reader.ReadLine();

while (line != null)

{

//make the structure

result.Add(MakeReady(remotePathUri, line));

line = reader.ReadLine();

}

reader.Close();

}//

response.Close();

}//

}

catch (WebException e)

{

System.Windows.Forms.MessageBox.Show(((HttpWebResponse)e.Response).StatusCode.ToString());

}

catch (Exception e)

{

System.Windows.Forms.MessageBox.Show(e.Message);

}

finally { }

return result;

}

Check user rights - ionut nedelea replied to Erik Little on 06-Nov-06 12:10 PM

I have tested your method and it works fine. I guess the problem is elsewhere. Have you given the rights on that user to list files on that directory? First check the attributes for the directory and try again.

First i - Erik Little replied to ionut nedelea on 06-Nov-06 12:44 PM

get a list of subDirectoys under the users root

FtpHelper.FtpUtil._UserName = "xxxxxxx";

FtpHelper.FtpUtil._PassWord = "xxxxxxx";

string ftp = "ftp://ftp.afcc1.com/Users/UserName";

string[] dirs = new string[] { "Projects", "Project-moms house" };

firstList ---> List<List<FtpHelper.FtpUtil.FileDirInfo>> projects = FtpHelper.FtpUtil.GetTree(ftp, dirs, 1, true);

Then i turn right around and get a list of each directoy or file under the subDirectorys

##I can start at the point of the subDirectoys and i get the list back ok then. so i have the permisson ok.. And i might have something wrong their; but i think it is ok

secondList ---> List<List<FtpHelper.FtpUtil.FileDirInfo>> project = FtpHelper.FtpUtil.GetTree(projects[0][1].RemotePathUri, new string[] { "" }, 1, true);

when i try to run the second list i get the errors

-----------

Here is the code that i use for the list. The first code i posted is great for the first level; however, i would like to see if direcotys have subDirs or files... and build that in an object an...

 

public static List<List<FileDirInfo>>

GetTree(string remotePathUri, string[] appendDirs, int subLevels, bool chechForChildren)

{

if (remotePathUri.EndsWith("/"))

remotePathUri = remotePathUri.Remove(remotePathUri.Length - 1);

//

List<List<FileDirInfo>> tree = new List<List<FileDirInfo>>();

List<FileDirInfo> branches = new List<FileDirInfo>();

//

//lines the directorys in the

//correct format as they are processed

string dirTracker = string.Empty;

try

{

for (int i = 0; i < subLevels; i++)

if (i == 0)

{

tree.Add(GetFileAndDirNames(remotePathUri + "/" + appendDirs[i]));

dirTracker = appendDirs[i];

}

else

{

dirTracker = dirTracker + "/" + appendDirs[i];

tree.Add(GetFileAndDirNames(remotePathUri + "/" + dirTracker));

}

}

catch (Exception) { tree = null; branches = null; }

finally { branches = null; }

return tree;

}


I may be wrong but i think the connection is still open...


Suggestion-- - Peter Bromberg replied to Erik Little on 06-Nov-06 01:38 PM

directory traversal commands and other commands are needed to do the kind of stuff you want to do, and they aren't included in the base set of built-in FTP commands in the FTPRequest object.

You *Can* create these custom commands for it, but the code to do so is quite ugly, so you can avoid wanting to jump out the window by switching to one of the freeware .net FTP libraries such as Enterprise DT FTP.  You can find it easily on the web.

ok.... i think i have tested that code a little and like using it i was just going to give
Erik Little replied to Peter Bromberg on 06-Nov-06 01:47 PM

.net a shot ...

Thanks for the help...


Erik

Can't see the problem - ionut nedelea replied to Erik Little on 06-Nov-06 01:54 PM
There is no connection open be sure of that. The 'using' takes care of that, you can even skip both calls to 'Close()'. I could't find the problem in your code and i belive it's not in there snippets you've sent.
Just found the problem and i can not believe i never thought to look their.
Erik Little replied to ionut nedelea on 06-Nov-06 03:54 PM

When i was building the string for the next ftpRequest i was leaving a whitespace in the strings..

Example of string that had to be cut up

"drwxrwxrwx   1 owner    group               0 Nov  5 11:50 Building Related"

FDI.Name = dirNamePart.Substring(dirNamePart.IndexOf(' '), dirNamePart.Length - dirNamePart.IndexOf(' ')).Trim(); <----Had to add the .Trim()



//The ':' is the last known unique char that i can find before an empty char

//that is before the directory of file name. Example of this look like:

//"drwxrwxrwx 1 owner group 0 Nov 5 16:25 Project Dog House"

dirNamePart = list.Substring(list.LastIndexOf(':'), list.Length - list.LastIndexOf(':'));

FDI.Name = dirNamePart.Substring(dirNamePart.IndexOf(' '), dirNamePart.Length - dirNamePart.IndexOf(' ')).Trim();

FDI.RemotePathUri = remotePathUri + "/" + FDI.Name;

FDI.ParentName = Path.GetFileName(remotePathUri);

//

Here is a starter FTP for someone that might need it - Erik Little replied to Peter Bromberg on 06-Nov-06 08:03 PM

I will say that it is  very nice starter!

http://www.constructionsupercenter.com/SoftWare/Example/NetWorking/FTP/ftp-Example(0).zip

erik

Steps to Resolve the issue and reasons - Joy chandrasekaran replied to Erik Little on 26-Feb-09 06:06 AM

Hi,

Normally this type of issue will come only from requesting ftp link spelling mistake.

for example: ftp://sampleServer/MyFile.txt" this is the link for download "MyFile.txt" from ftp server "sample". But the file name is in FTP is "MyFile.TXT".

When you requesting the above link will give the error like below.

"The remote server returned an error:(550) File Unavailable (eg. File Not found, no access)"

to solve this issue by requesting following link

"ftp://sampleServer/MyFile.TXT"  instead of  "ftp://sampleServer/MyFile.txt"

Thanks

Joy..


krishan chandel replied to Erik Little on 05-Jun-12 12:01 AM
end of post