Click here to Skip to main content
11,715,160 members (73,777 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0
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?

string ftpPassword = ConfigurationManager.AppSettings["ftpPassword"].ToString();
    string uri = remoteDirectory;
    FileInfo fileInf = new FileInfo(FileToUpload);
    // Create FtpWebRequest object from the Uri provided
    FtpWebRequest reqFTP = null;
    reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
    reqFTP.Credentials = new NetworkCredential(ftpUsername, ftpPassword);
    reqFTP.KeepAlive = false;
    reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
    // Specify the data transfer type.
    reqFTP.UseBinary = true;
    // Notify the server about the size of the uploaded file
    reqFTP.ContentLength = fileInf.Length;
    // The buffer size is set to 2kb
    int buffLength = 2048;
    byte[] buff = new byte[buffLength];
    int contentLen;
    // open file to be uploaded
    using (FileStream fs = fileInf.OpenRead())
    {
    try
    {
    // Stream to which the file to be upload is written
    using (Stream strm = reqFTP.GetRequestStream())
    {
    // Read from the file stream 2kb at a time till Stream content ends
    contentLen = fs.Read(buff, 0, buffLength);
    while (contentLen != 0)
    {
    // Write Content from the file stream to the FTP Upload Stream
    strm.Write(buff, 0, contentLen);
    contentLen = fs.Read(buff, 0, buffLength);
    }
    }
    reqFTP = null;
    ////Update the database with the new image location and delete the img from the uploadedimages folder
    //DataAccess.UpdateImageDB(item.ProductID, item.ImgFolder + "/" + item.IMG);
    System.IO.File.Delete(fileInf.ToString());
    }
    {
    Console.WriteLine(ex.Message, "Upload Error");
    }
Posted 3-Dec-10 6:20am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

"550" in FTP context should mean "Permission Denied". Seems you have no permission.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 495
1 Richard MacCutchan 275
2 Maciej Los 259
3 ManasKumarM 155
4 Frankie-C 125
0 Sergey Alexandrovich Kryukov 775
1 CHill60 415
2 Richard MacCutchan 405
3 Maciej Los 389
4 OriginalGriff 320


Advertise | Privacy | Mobile
Web03 | 2.8.150901.1 | Last Updated 15 Dec 2010
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100