Click here to Skip to main content
15,886,823 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
FtpWebRequest reqFTP;                      
        Uri serverFile = new Uri("ftp://10.14.21.80/UKSALES/TechM.war");         
        reqFTP = (FtpWebRequest)FtpWebRequest.Create(serverFile);         
        reqFTP.Method = WebRequestMethods.Ftp.Rename;         
        reqFTP.UseBinary = true;
        reqFTP.Credentials = new NetworkCredential("anonymous", "");
        reqFTP.RenameTo = "ftp://10.14.21.80/UKSALES/Backup\\TechM.war";   
        FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();



But this doesn’t seem to work – I get the following error:
The remote server returned an error: (550) File unavailable (e.g., file not found, no access). Please any help on this issue.. Thank you
Posted
Updated 15-Nov-11 17:41pm
v2
Comments
sabbi26 15-Nov-11 23:42pm    
Check the user have permissions to read and write the file in file server.
[no name] 15-Nov-11 23:43pm    
Does the user have permission to create directories here?

Are the backslashes a typo?
skathirmca1 16-Nov-11 0:05am    
yes,user can able to create directories..

1 solution

what i feel is this can happen with two reasons.
1) You have not had proper access to FTP directory.
2) File is unavailable in the specified location.

authorization - use proper user name and password. some times it will not responded
to "annonimus" user account which haven't had password.

availability of files - you can easily check file by using
Directory.GetFiles(filepath);
this will return string[] list of file names and then you can check the specifiled file availability.

Below codes are for download files from FTP location. Instead of web response class i used web client.
put your values to RequestUri,RequestUsername,RequestPassword, uri, strDownloadFilepath, RequestUri + strFile

private void downloadFiles()
{
try
{
//Get File List From server FTP folder
string[] files =Directory.GetFiles(RequestUri);

//check files in the server for continue process
if (files != null && files.Count() != 0)
{
string strDownloadFilepath = string.Empty;

System.Net.WebClient webClient = new System.Net.WebClient();
//Set Network Credentials
webClient.Credentials = new NetworkCredential(RequestUsername, RequestPassword);


foreach (string strFile in files)
{
//set full file path to download (Path+fileName)
strDownloadFilepath = LocalDownloadPath + strFile;
//set the URI
System.Uri uri = new Uri(RequestUri + strFile);
try
{
//Download in sync
webClient.DownloadFile(uri, strDownloadFilepath);
}
catch (WebException ex)
{
//write log


}


}
}
}
catch(WebException ex)
{

}
webClient.Dispose();
}

for more refer
http://dinidusoft-nothingisimpossible.blogspot.com/2010/03/downloaddeleteupload-ftp-files-c.html
 
Share this answer
 
Comments
skathirmca1 16-Nov-11 1:31am    
Thanks for quick respones..

i had tried but it's not working please find the below my code, if i gave wrong, plase correct my code..


private void downloadFiles()
{
try
{
//Get File List From server FTP folder

string[] files = Directory.GetFiles("ftp://10.14.21.80/UKSALES\\TechM.war");


//check files in the server for continue process
if (files != null && files.Count() != 0)
{
string strDownloadFilepath = string.Empty;

System.Net.WebClient webClient = new System.Net.WebClient();
//Set Network Credentials
webClient.Credentials = new NetworkCredential("anonymous", "");


foreach (string strFile in files)
{
//set full file path to download (Path+fileName)
strDownloadFilepath = "ftp://10.14.21.80/UKSALES/Backup\\TechM.war";
//set the URI
System.Uri uri = new Uri("ftp://10.14.21.80/UKSALES/TechM.war");
try
{
//Download in sync
webClient.DownloadFile(uri, strDownloadFilepath);
}
catch (WebException ex)
{
//write log


}


}
}
}
catch (WebException ex)
{

}
//webClient.Dispose();
}

Please find the below errors : The given path's format is not supported.
dinidusoft123 16-Nov-11 3:12am    
i think your ftp folder can not access because of credential problems.
Why do'nt you try another user instead of "anonimas"

try this and this is the simplest one
<pre>strDownloadFilepath </pre> is the directory that is store the downloaded file.

<pre> private void downloadFiles()
{
try
{

string strDownloadFilepath = string.Empty;
System.Net.WebClient webClient = new System.Net.WebClient();
//Set Network Credentials
webClient.Credentials = new NetworkCredential("Everyone", "");
//foreach (string strFile in files)
//{
//set full file path to download (Path+fileName)

strDownloadFilepath = @"c:\Newfolder";
//set the URI
System.Uri uri = new Uri("ftp://10.14.21.80/UKSALES/TechM.war");
try
{
//Download in sync
webClient.DownloadFile(uri, strDownloadFilepath);
}
catch
(WebException ex)
{
throw ex;
//write log
// }
// }
}
}
catch (WebException exx) { } //webClient.Dispose(); }
}</pre>
skathirmca1 16-Nov-11 5:33am    
Hi ,
Thanks for your good answer. i had tried but it's not working.. moreover i need file move to with ftp server . example :

ftp://10.2.2.2/ftpfolder/folder\test.txt
ftp://10.2.2.2/ftpfolder/folder\backup\test.txt
dinidusoft123 16-Nov-11 6:14am    
have you try this one...
http://stackoverflow.com/questions/4864925/how-can-i-use-ftp-to-move-files-between-directories
skathirmca1 16-Nov-11 6:19am    
yes, i had tried but i am getting error."The remote server returned an error: (550) File unavailable (e.g., file not found, no access). " thanks so mcuh for helping me..

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