简体   繁体   中英

FTP error: (553) File name not allowed

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM