file upload to ftp server not localhost

hi guys i am getting aproblem while upload file to ftp server..

i am getting access denied error....i search a lot about this error ..and give all permission to that folder but nothing working..

i have pleask 9.0 panel...

i am using this code..

and getting access denied..
SqlCommand cmdInsert;
        con.Open();
        string filename = "";
        string guid = System.Guid.NewGuid().ToString();
        string uni = guid.Substring(0, 12);
        string strInsert = "Insert into documents ( docname, docpath, user_id ) Values (@docname, @docpath, '"+Session["user_id"].ToString()+"' )";
        cmdInsert = new SqlCommand(strInsert, con);
        cmdInsert.Parameters.Add("@docname", TextBox1.Text);

        cmdInsert.Parameters.Add("@docpath", uni + Path.GetExtension(FileUpload1.FileName));
        if (FileUpload1.HasFile)
        {
            if (cmdInsert.ExecuteNonQuery() == 1)
            {
                FileUpload1.SaveAs(@Server.MapPath("~/upload/") + uni + Path.GetExtension(FileUpload1.FileName));

                Response.Write("<script type='text/javascript'> alert('File Uploaded Successfully'); location.href='upload.aspx'; </scr" + "ipt>");

            }

        }
        
        con.Close();

Open in new window

mahajan344Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dshrivallabhCommented:
The server you are trying to put your file into must have the path as a shared path

You must add the user trying to upload to sharing and security rights of that folder.

If the folder is encrypted then you need a certificate authority providing you access to that folder
0
mahajan344Author Commented:
but i have given all permission to upload folder from pleask panel...
0
masterpassCommented:
Try this

http://dotnetslackers.com/Community/blogs/kaushalparik/archive/2008/05/24/code-to-upload-file-to-ftp-server.aspx

The code you are using will only save the file to localhost and not FTP
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

mahajan344Author Commented:
not working...giving same error....dude please help me its very urgent..
0
masterpassCommented:
Can you post the code you are using for FTP ? If its the same it won't work ... Just refer to post ID: 28519394
0
mahajan344Author Commented:
i am using below code and its giving

and its giving this error

"The remote server returned an error: (550) File unavailable (e.g., file not found, no access)."

on line

" Stream ftpStream = request.GetRequestStream();"
FileInfo toupload = new FileInfo(this.FileUpload1.FileName);
        FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://abc.net"+"/"+toupload.Name);
        request.Method = WebRequestMethods.Ftp.UploadFile;
        request.Credentials = new NetworkCredential("ftpusername", "ftppassword");
        Stream ftpStream = request.GetRequestStream();
        FileStream file = File.OpenRead(Path.GetFullPath(FileUpload1.FileName));
        int lenth = 1024;
        byte[] buffer = new byte[lenth];
        int bytesread = 0;
        do
        {
            bytesread = file.Read(buffer, 0, lenth);
            ftpStream.Write(buffer, 0, bytesread);
        }
        while (bytesread != 0);
        file.Close();
        ftpStream.Close();
        Response.Write("abc");

Open in new window

0
masterpassCommented:
Try this
FileInfo toupload = new FileInfo(this.FileUpload1.FileName);
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://abc.net"+"/"+toupload.Name);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential("ftpusername", "ftppassword");
StreamReader ftpStream =  new StreamReader(FileUpload1.FileContent);
byte[] fileContents = Encoding.UTF8.GetBytes(ftpStream.ReadToEnd());
ftpStream.Close();
request.ContentLength = fileContents.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
response.Close();

Open in new window

0
mahajan344Author Commented:
giving error
"The name 'Encoding' does not exist in the current context"
0
masterpassCommented:
use System.Text

byte[] fileContents = System.Text.Encoding.UTF8.GetBytes(ftpStream.ReadToEnd());
0
mahajan344Author Commented:
got same error as getting before...



"The remote server returned an error: (550) File unavailable (e.g., file not found, no access)."

on line

" Stream ftpStream = request.GetRequestStream();"
0
masterpassCommented:
permissions issue ... ask your admin to allow other domain access to your FTP. think that may solve
0
masterpassCommented:
Also If you are behind a firewall, ask the admin to allow FTP access out
0
mahajan344Author Commented:
buddy i am admin.. i have control panel of pleask .. i have created this doamin and ftp and gave additional read write permission too...
i am using plesk 9.0 ................
then why its not uploading
0
masterpassCommented:
How about the firewall rules ?
0
mahajan344Author Commented:
firewall rules...??
didn't get u...

u mean at plesk or on my OS ??
0
masterpassCommented:
Do you use a firewall? ... Usually the ftp server comes under the DMZ zone ... so it's possible that a firewall you are using may deny ftp file upload ....

0
mahajan344Author Commented:
ohh.. not at all ..

isn't there any working solution... i googled a lot too.. and its been 2 days since i am looking for this solution that is why i posted it here....

but still getting same error :(
0
mahajan344Author Commented:
is there no one who can help.. me
0
masterpassCommented:
0
mahajan344Author Commented:
nooopp... has anyone tested ftp upload code on plesk panel..
my clint gonna kill me...cause its been 2 days since i am seaching for ftp upload code...
0
masterpassCommented:
don't mind me asking this ... Have you given WRITE permission?
0
mahajan344Author Commented:
yes ofcourse...........
0
mahajan344Author Commented:
now its all working but i am not able to upload bigger files..
i am uploading 26mb file and when uploading is 20% done it says connection was reset.. ??

i have mentioned connection timeout="7200" in web.config file... but nothing working
0
masterpassCommented:
In your web.config, look for this

<httpRuntime
executionTimeout="90"
maxRequestLength="4096"
useFullyQualifiedRedirectUrl="false"
minFreeThreads="8"
minLocalRequestFreeThreads="4"
appRequestQueueLimit="100"
enableVersionHeader="true"
/>

just take a look at the maxRequestLength="4096" or what ever is set in your application, all you need to do is change the value to some other value of your choice (8192 for 8 Mb, 16384 for 16 Mb, 65536 for 64 Mb, and so on...)

I hope this helps...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mahajan344Author Commented:
yup i was looking for this thing thanks a lot and thanks other too
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
File Sharing Software

From novice to tech pro — start learning today.