By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,024 Members | 2,027 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,024 IT Pros & Developers. It's quick & easy.

Uploading folder to ftp

P: 37
I am trying to upload images to the ftp. I need to have it in a compressed folder called by a specific name and then upload that folder to a specific directory. Each time I try, I get an error The remote server returned an error: (550) File unavailable
This code works fine when I am trying to upload one image at a time. Here I am trying to upload a whole folder. I checked the uri (I copied it from the debugging) and it went there just fine. Is there a different way that I have to do the upload folders?

It doesn't really sound like it can be a permissions problem, because I am able to upload a file via filezilla. I am also able to use a command prompt and cd into the proper folder. Anyone know what the problem is? I am pretty desperate?

Expand|Select|Wrap|Line Numbers
  1.  
  2.   string ftpPassword = ConfigurationManager.AppSettings["ftpPassword"].ToString();
  3.       string uri = remoteDirectory;
  4.       FileInfo fileInf = new FileInfo(FileToUpload);
  5.       // Create FtpWebRequest object from the Uri provided
  6.       FtpWebRequest reqFTP = null;
  7.       reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
  8.       reqFTP.Credentials = new NetworkCredential(ftpUsername, ftpPassword);
  9.       reqFTP.KeepAlive = false;
  10.       reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
  11.       // Specify the data transfer type.
  12.       reqFTP.UseBinary = true;
  13.       // Notify the server about the size of the uploaded file
  14.       reqFTP.ContentLength = fileInf.Length;
  15.       // The buffer size is set to 2kb
  16.       int buffLength = 2048;
  17.       byte[] buff = new byte[buffLength];
  18.       int contentLen;
  19.       // open file to be uploaded
  20.       using (FileStream fs = fileInf.OpenRead())
  21.       {
  22.       try
  23.       {
  24.       // Stream to which the file to be upload is written
  25.       using (Stream strm = reqFTP.GetRequestStream())
  26.       {
  27.       // Read from the file stream 2kb at a time till Stream content ends
  28.       contentLen = fs.Read(buff, 0, buffLength);
  29.       while (contentLen != 0)
  30.       {
  31.       // Write Content from the file stream to the FTP Upload Stream
  32.       strm.Write(buff, 0, contentLen);
  33.       contentLen = fs.Read(buff, 0, buffLength);
  34.       }
  35.       }
  36.       reqFTP = null;
  37.       ////Update the database with the new image location and delete the img from the uploadedimages folder
  38.       //DataAccess.UpdateImageDB(item.ProductID, item.ImgFolder + "/" + item.IMG);
  39.       System.IO.File.Delete(fileInf.ToString());
  40.       }
  41.       {
  42.       Console.WriteLine(ex.Message, "Upload Error");
  43.       }
  44.  
Dec 15 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.