0

I am trying to ftp a file but i get the following error:

The remote server returned an error: (553) File name not allowed. at System.Net.FtpWebRequest.SyncRequestCallback(Object obj) at System.Net.FtpWebRequest.RequestCallback(Object obj) at System.Net.CommandStream.Dispose(Boolean disposing) at System.IO.Stream.Close() at System.IO.Stream.Dispose() 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.GetRequestStream()

This exception occurs at the following line marked in my snippet below.

System.Net.FtpWebRequest clsRequest = (System.Net.FtpWebRequest)System.Net.WebRequest.Create("ftp://" + destination.FTPSite + outputFile);
clsRequest.Credentials = new System.Net.NetworkCredential(destination.FTPUserName, destination.FTPPassword);
clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile;
clsRequest.Timeout = Properties.Settings.Default.FtpTimeOut;

// read in file...
byte[] bFile = System.IO.File.ReadAllBytes(localFile);

// upload file...
System.IO.Stream clsStream = clsRequest.GetRequestStream(); <<----
clsStream.Write(bFile, 0, bFile.Length);
clsStream.Close();
clsStream.Dispose();

It's trying to send to the following location on the ftp site: send/republicservices/invoice/

File: Republic_20140421_230019.inv

This code originally worked in VB.net but now am getting issues in the c# version. Any ideas why? This code also uploads about 6 other files daily without issue.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
user1732364
  • 925
  • 4
  • 28
  • 58

2 Answers2

0

I came faced the same problem however I solved it myself. The main 2 reasons of this problem are 1. Permission problem (rare) happens when you don't have permission to read/write to that file and 2. Error in path (common) happens when your ftp path is wrong. Without seeing your path it is impossible to say what's wrong but one must remember the things a. Unlike browser FTP doesn't accept some special characters like ~ b. If you have several user accounts under same IP, do not include username or the word "home" in path c. Don't forget to include "public_html" in the path (normally you need to access the contents of public_html only) otherwise you may end up in a bottomless pit

Bibaswann Bandyopadhyay
  • 3,389
  • 2
  • 31
  • 30
-1

I think your problem is at:

System.Net.FtpWebRequest clsRequest = (System.Net.FtpWebRequest)System.Net.WebRequest.Create("ftp://" + destination.FTPSite + outputFile);

Try this:

    System.Net.FtpWebRequest clsRequest = (System.Net.FtpWebRequest)System.Net.WebRequest.Create(String.Format(@"ftp://{0}{1}", destination.FTPSite, outputFile));
sloukidis
  • 1
  • 2
  • I'll give this a shot and get back with you on the results!! – user1732364 Apr 23 '14 at 12:39
  • `String.Format(@"ftp://{0}{1}", destination.FTPSite, outputFile)` instead of `@"ftp://" + destination.FTPSite + outputFile` – sloukidis Apr 24 '14 at 08:41
  • What I mean is: The output of the two string formatting variants is the same. This cannot possibly change the outcome of the program. – usr Apr 24 '14 at 08:43
  • I tried this change over a few days and still have the same issue. Any other thoughts? If i can't solve it through .NET i'll just rewrite it using Chilkat which id 100% rather not do. – user1732364 Apr 29 '14 at 13:06
  • I found the issue, the ftp site paths were being changed by the end users...sigh – user1732364 May 16 '14 at 12:53