FTP from my application
-
9. března 2012 18:00
I have been looking around and trying different samples on allowing FTP access within my app to upload a file or files..
and no matter what sample i try, i get the following message..
{"The remote server returned an error: (550) File unavailable (e.g., file not found, no access)."}
right now im working with a very simple form..
opendialog control, and 2 buttons.. it opens the dialog window, you select your file and then hit the upload..
dont think you can get more simple than that..
The error message comes up on this line:
private void btnUpload_Click(object sender, EventArgs e) { string upURL = "ftp://ftp.site.com/"; FileInfo toUpload = new FileInfo(textBox1.Text); FtpWebRequest request = (FtpWebRequest)WebRequest.Create(upURL + "/" + textBox1.Text); request.Method = WebRequestMethods.Ftp.UploadFile; // This example assumes the FTP site uses anonymous logon. request.Credentials = new NetworkCredential("login", "password"); Stream ftpStream = request.GetRequestStream(); <<<---- Error shows up on this line FileStream file = File.OpenRead(textBox1.Text); int length = 1024; byte[] buffer = new byte[length]; int bytesRead = 0; do { bytesRead = file.Read(buffer, 0, length); ftpStream.Write(buffer, 0, bytesRead); } while (bytesRead != 0); file.Close(); ftpStream.Close(); MessageBox.Show("Upload Complete!"); }
Všechny reakce
-
9. března 2012 20:38
Have you tried this library too: http://ftplib.codeplex.com/?
Marco Minerva [MCPD]
Blog: http://blogs.ugidotnet.org/marcom
Twitter: @marcominerva -
9. března 2012 21:34
I looked at that, but looking thru the comments, doesnt seem to work for windows mobile app, which is where i eventually want my app to run.. right now since its easier, im working on app for my pc.. what im working on for my phone is an app to back up my files from my phone to my website.
thanks for the link..
-
13. března 2012 7:08Moderátor
Hi Cubangt,
I think there are some errors in your ftp uri.
First, you should not combine “/’” with the upURL again.
Second, what’s the value of textBox1.Text, read the article below and check the uri.
http://blogs.msdn.com/b/adarshk/archive/2004/09/13/229069.aspx
The following sample on MSDN shows how to upload a file to an FTP server.http://msdn.microsoft.com/en-us/library/ms229715.aspx
In addition, are you developing for Windows Phone 7? If so, you can get better help in the Developing for Windows Phone 7 forum.
Anyway, please let us know the result.
Best Regards,
Bob Wu [MSFT]
MSDN Community Support | Feedback to us
- Upravený Bob Wu-MTMicrosoft Contingent Staff, Moderator 13. března 2012 7:09 add link
- Označen jako odpověď Bob Wu-MTMicrosoft Contingent Staff, Moderator 26. března 2012 3:07
-
15. března 2012 16:47This test app is running on my pc.. eventually i would like it to run on my WM6.5 phone.. dont use WM7 and wont anytime soon..
-
16. března 2012 7:02ModerátorHi Cubangt,
Can you run it on the PC now with my suggestions?
Best Regards,Bob Wu [MSFT]
MSDN Community Support | Feedback to us