我試圖將圖像上載到ftp。我需要將它放在由特定名稱調用的壓縮文件夾中,然後將該文件夾上傳到特定目錄。每次我嘗試時,我得到一個錯誤遠程服務器返回一個錯誤:(550)文件不可用 此代碼工作正常,當我試圖一次上傳一個圖像。這裏我試圖上傳整個文件夾。我檢查了uri(我從調試中複製了它),並且它很好。有沒有不同的方式,我必須做上傳文件夾?我認爲這是一個寫權限問題,但我可以手動登錄並將文件夾上傳到適當的位置。然後我試圖獲得我能夠的目錄列表。我無法將文件夾上傳到根目錄。我非常絕望!我甚至不知道在哪裏谷歌!將文件夾上傳到ftp子文件夾返回錯誤(550)文件不可用,無法訪問
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");
}
我知道該文件夾存在。我從數據庫中提取文件夾名稱。另外,當我瀏覽它時,我將uri複製並粘貼到瀏覽器中,並且沒有任何問題。 – SSs 2010-12-08 14:02:18