FtpWebRequest returns error 550 File unavailable

This error can be caused because of several reasons like file is not present on server, security permissions on file etc. etc. First you need to find out the exact cause of error. This can be achieved by using following code- try { //Your code } catch(WebException e) { String status = ((FtpWebResponse)e.Response).StatusDescription; } Once … Read more

How to improve the Performance of FtpWebRequest?

I have done some experimentation (uploading about 20 files on various sizes) on FtpWebRequest with the following factors KeepAlive = true/false ftpRequest.KeepAlive = isKeepAlive; Connnection Group Name = UserDefined or null ftpRequest.ConnectionGroupName = “MyGroupName”; Connection Limit = 2 (default) or 4 or 8 ftpRequest.ServicePoint.ConnectionLimit = ConnectionLimit; Mode = Synchronous or Async see this example My … Read more

How to check if an FTP directory exists

Basically trapped the error that i receive when creating the directory like so. private bool CreateFTPDirectory(string directory) { try { //create the directory FtpWebRequest requestDir = (FtpWebRequest)FtpWebRequest.Create(new Uri(directory)); requestDir.Method = WebRequestMethods.Ftp.MakeDirectory; requestDir.Credentials = new NetworkCredential(“username”, “password”); requestDir.UsePassive = true; requestDir.UseBinary = true; requestDir.KeepAlive = false; FtpWebResponse response = (FtpWebResponse)requestDir.GetResponse(); Stream ftpStream = response.GetResponseStream(); ftpStream.Close(); response.Close(); … Read more

FtpWebRequest Download File

I know this is an old Post but I am adding here for future reference. Here is a solution that I found: private void DownloadFileFTP() { string inputfilepath = @”C:\Temp\FileName.exe”; string ftphost = “xxx.xx.x.xxx”; string ftpfilepath = “/Updater/Dir1/FileName.exe”; string ftpfullpath = “ftp://” + ftphost + ftpfilepath; using (WebClient request = new WebClient()) { request.Credentials = … Read more

How to check if file exists on FTP before FtpWebRequest

var request = (FtpWebRequest)WebRequest.Create (“ftp://ftp.domain.com/doesntexist.txt”); request.Credentials = new NetworkCredential(“user”, “pass”); request.Method = WebRequestMethods.Ftp.GetFileSize; try { FtpWebResponse response = (FtpWebResponse)request.GetResponse(); } catch (WebException ex) { FtpWebResponse response = (FtpWebResponse)ex.Response; if (response.StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable) { //Does not exist } } As a general rule it’s a bad idea to use Exceptions for functionality in your code like … Read more

tech