Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FTP through C# generates NO BATCHES FOR TRANSMISSION error 1

Status
Not open for further replies.

brage98

IS-IT--Management
Sep 8, 2010
27
CA
I have a code to connect to an FTP server...
When I paste the "RequestURI" in my IE, I enter the password etc and I can download the file from FTP no problem

When I run my code, I get the following error:
Code:
The remote server returned an error: (550) File unavailable (e.g., file not found, no access).
550 *** ERROR *** NO BATCHES FOR TRANSMISSION

When I use "CoreFTP", I get the following error (however the file does get downloaded):
Code:
The remote server returned an error: (550) File unavailable (e.g., file not found, no access).
550 *** ERROR *** NO BATCHES FOR TRANSMISSION


here's my code-snipped:
Code:
        private void Download(string file)
        {                       
            try
            {                
                string uri = host + "/" + remoteDir + "/" + file;
                Uri serverUri = new Uri(uri);
                if (serverUri.Scheme != Uri.UriSchemeFtp)
                {
                    return;
                }       
                FtpWebRequest reqFTP;                
                reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));                                
                reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);                
                reqFTP.KeepAlive = false;                
                reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;       
                reqFTP.UseBinary = true;
                reqFTP.Proxy = null;                 
                reqFTP.UsePassive = false; // <--- Also tried true
                FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse(); // <--- Error occurs

                Stream responseStream = response.GetResponseStream();
                FileStream writeStream = new FileStream(Path.Combine(localDestnDir, file), FileMode.Create);                
                int Length = 2048;
                Byte[] buffer = new Byte[Length];
                int bytesRead = responseStream.Read(buffer, 0, Length);               
                while (bytesRead > 0)
                {
                    writeStream.Write(buffer, 0, bytesRead);
                    bytesRead = responseStream.Read(buffer, 0, Length);
                }                
                writeStream.Close();
                response.Close(); 
            }
            catch (WebException wEx)
            {
                this.DisplayMessage(wEx.Message);
                this.DisplayMessage((wEx.Response as FtpWebResponse).StatusDescription);
            }
            catch (Exception ex)
            {
                this.DisplayMessage(ex.Message);
            }
        }
 
since the error is the same regardless of how you access the ftp site, I would say the problem is on the server, not the client. enable logging on the remote server to figure out why it's failing exactly. credentials, missing file or something else?

also display the entire exception (type, message, stack trace), not just the message.
Code:
try
{
   ...
}
catch (Exception e)
{
   DisplayMessage(ex.ToString());
}
no need to catch WebException and cast the type. ToString will dump everything about the exception.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
thanks for the reply.
I thought it could be the FTP server as well. However, I'm wondering, if it was a server issue, I probably wouldn't be able to grab the file through my browser.

Also, CoreFTP does download the file, with error; but it does download it.

Currently permissions-config on the ftp folder is 0:
-CR--M----

should this be changed? to what?

Thanks!
 
Also, CoreFTP does download the file, with error; but it does download it.
which should be a sign that something isn't right on the server. I would consider it a problem that you are getting errors the file is missing, yet you are downloading it.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
yeah fair enough.
I don't have access to this server. I'm in touch with the administrators of the server. meanwhile I'd love to speed the process up by letting them know what they should be doing.
Would you say this is a security/permission issue on the server?

Here's the error from the exception:
Code:
Stack Track:
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.GetResponse() at Template._Default.Download(String file) in 

Type:
System

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

here's the error from WebException:
Code:
The remote server returned an error: (550) File unavailable (e.g., file not found, no access).
550 *** ERROR *** NO BATCHES FOR TRANSMISSION
 
Well, found the answer:

Let me explain:
Admins of the server have created an ftp that points to /folder:
ftp://sss.bbb.com ----> starts at /Folder

I'm creating URI such that it writes
ftp://sss.bbb.com/Folder/theFiletoDownload.ext

obviously that's wrong, as "Folder" cannot be found.

So I've replaced the following code
Code:
string uri = host + "/" + remoteDir + "/" + file;
with
Code:
string uri = host + @"/" + file;
 
excellent! you can tighten up your code using
Code:
var uri = string.Format(@"{0}/{1}", host, file);

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
oh sure.
I was just trying to get the thing going first. Thanks for thinking this through with me ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top