Problem fileupload with ftp in asp.net


i have asp.net web page has fileupload to let user upload any file he want from his pc to web site ftp

the problem is that code work good in my pc local but when i upload the web site the code not work and show me that error

the error is :

Could not find file 'C:\Documents and Settings\XPPRESP3\Desktop\New Folder (2)\test.zip'


private void Upload(string filename)
{
FileInfo fileInf = new FileInfo(filename);
string uri = "ftp://"+ftpServerIP+"/wwwroot/Program/"+ fileInf.Name;
FtpWebRequest reqFTP;

reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://"+ftpServerIP+"/wwwroot/Program/"+ fileInf.Name));

reqFTP.Credentials = new NetworkCredential(ftpUserID, 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;

FileStream fs = fileInf.OpenRead();

try
{
Stream strm = reqFTP.GetRequestStream();
contentLen = fs.Read(buff, 0, buffLength);

while (contentLen != 0)
{
strm.Write(buff, 0, contentLen);
contentLen = fs.Read(buff, 0, buffLength);
}

strm.Close();
fs.Close();
}
catch (Exception ex)
{

}
}

and recive it in button by :

Upload(FileUpload1.PostedFile.FileName);

any one can help me in this please

hello to all

any one can help me please

Hi,

It does not look like Aspose.Form problem.

I think you are trying to read a file that does not exist on the web server. FileUpload1.PostedFile.FileName does not give the contents of the posted file. It only returns fully qualified name of the file on client machine.

When a file is uploaded using FileUpload control, the file’s contents are exposed as a System.IO.Stream object (FileUpload1.PostedFile.InputStream) and this is the way the users are expected to access the contents of a posted file using FileUpload control.

The other method you can use is that save the posted file on the web server using below code and then upload it.

FileUpload1.SaveAs(Server.MapPath("~/Folder1\\" + FileUpload1.FileName));

string sourceFile = Server.MapPath("~/Folder1\\" + FileUpload1.FileName);

After uploading, you can delete the saved file by using the below code.

File.Delete(Server.MapPath("~/Folder1\\" + FileUpload1.FileName));

Best Regards,

Hi,

It seems that the file 'C:\Documents and Settings\XPPRESP3\Desktop\New Folder (2)\test.zip' exists on your local system, and not on the webserver.

Thank you too for all who assist me in this problem, I replaced the previous code in this line of code only worked well

FileUpload1.SaveAs(Server.MapPath("~/Folder1\\" + FileUpload1.FileName));