Tuesday, August 28, 2012

Silverlight 4 FTP File Upload

Silverlight 4 FTP File Upload

Hy,
is it possible to upload a file to an ftp server with silverlight 4 sockets?
I can't use a normal webservice as a proxy between silverlight and the ftp server
Thanks!

Answers & Comments...

Answer: 1
Only with a Full trust application.
The reason is that with a in-browser Silverlight app, the port range for sockets must be within the 4502-4534 range (FTP is 21). Its for security purposes.
But you can pass through a service which do the job.



Answer: 2
 i dont know if you are uploading by visual studio... but you can always publish youre project to file and than use total comander to conect with ftp and just copy -> paste.



Answer: 3 I want to upload a file in silverlight to a ftp server and not the silverlight application to the ftp server.

does anyone know a tutorial to do this?

Answer: 4
I told you, you can only can with a full trust application, or by calling a wcf service which do the upload for you.



Answer: 5 My application is running in elevated trust mode ...

Answer: 6
Then you can use sockets to connect to your FTP server. But you have to implement the protocol by yourself.
http://www.faqs.org/rfcs/rfc959.html



Answer: 7
I managed to connect my ftp server.
I wanted to send the string "username: xxx" but the ftp server thought, that every single character was a command:
(000005) 5/10/2010 15:54:48 PM - (not logged in) (127.0.0.1)> u
(000005) 5/10/2010 15:54:48 PM - (not logged in) (127.0.0.1)> 500 Syntax error, command unrecognized.
(000005) 5/10/2010 15:54:48 PM - (not logged in) (127.0.0.1)> s
(000005) 5/10/2010 15:54:48 PM - (not logged in) (127.0.0.1)> 500 Syntax error, command unrecognized.
(000005) 5/10/2010 15:54:48 PM - (not logged in) (127.0.0.1)> e
(000005) 5/10/2010 15:54:48 PM - (not logged in) (127.0.0.1)> 500 Syntax error, command unrecognized.
(000005) 5/10/2010 15:54:48 PM - (not logged in) (127.0.0.1)> r

             (000005) 5/10/2010 15:54:48 PM - (not logged in) (127.0.0.1)> 500 Syntax error, command unrecognized.


Answer: 8
Can you show the code you use to send the commands?



Answer: 9
Here is the code:
private void btnFtpUpload_Click(object sender, RoutedEventArgs e)          {              var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);              var args = new SocketAsyncEventArgs();                             args.RemoteEndPoint = new DnsEndPoint("localhost", 21);                                      args.Completed +=                  delegate                  {                      Thread.Sleep(1000);                     SendString("username: xxx",                                 delegate                                 {                                     SendString("password: xxx", delegate                                     {                                       }                                 }, socket);                  };              socket.ConnectAsync(args);          }  public void SendString(string dataToSend,Action callback,Socket socket)          {           byte[] buffer = Encoding.UTF8.GetBytes(dataToSend);                SocketAsyncEventArgs args = new SocketAsyncEventArgs();              args.SetBuffer(buffer, 0, buffer.Length);                args.Completed += delegate(object sender, SocketAsyncEventArgs e)                                    {                                        if(e.SocketError == SocketError.Success)                                        {                                            callback();                                        }                                        else                                        {                                                                                    }                                    };              socket.SendAsync(args);          }  


Answer: 10
This is weird. It looks like Silverlight send your string char by char. Did you check with Wireshark to see what is sent?
BTW are you sure about your commands? I was reading the RFC 959 (FTP) and I saw that the command was

USER <SP> <username> <CRLF>
In your case you just send : "username: xxx" instead of "user xxx \r\n"


Answer: 11
ajax upload
FileUltimate is an ASP.NET file upload control which you can add directly to your existing ASP.NET (.aspx) pages.The control renders a user interface similar to "Windows Explorer" within the page which displays the contents of the target folder and accepts multiple file uploads from users. Actions can be limited by permissions and quota limits on folders. During file uploading, detailed information such as transfer speed and estimated time of completion are displayed along with the progress bar. This ASP.NET upload control supports browser upload, ajax upload and flash upload modes.


Answer: 12
Hi there!
I had some time and implemented a rudimental ftp client for Silverlight 5: https://github.com/dittodhole/sharpLightFtp
Kind regards,
Andreas Niedermair




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog