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);
FtpWebRequest reqFTP = null;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
reqFTP.Credentials = new NetworkCredential(ftpUsername, ftpPassword);
reqFTP.KeepAlive = false;
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
reqFTP.UseBinary = true;
reqFTP.ContentLength = fileInf.Length;
int buffLength = 2048;
byte[] buff = new byte[buffLength];
int contentLen;
using (FileStream fs = fileInf.OpenRead())
{
try
{
using (Stream strm = reqFTP.GetRequestStream())
{
contentLen = fs.Read(buff, 0, buffLength);
while (contentLen != 0)
{
strm.Write(buff, 0, contentLen);
contentLen = fs.Read(buff, 0, buffLength);
}
}
reqFTP = null;
System.IO.File.Delete(fileInf.ToString());
}
{
Console.WriteLine(ex.Message, "Upload Error");
}