C# Ftp client

  • Thread starter Thread starter Boris
  • Start date Start date
B

Boris

I am trying to develop C# ftp client to upload files to remote host.
Whenever, I execute System.Net.Sockets.Socket.Connect method, .Net Framework
raises the following exception

Request for the permission of type System.Net.SocketPermission, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.

Why does this happen?

Thanks,
-Boris
 
Hi,

This may seems like a silly question, but are you running it from a network
share?

It seems like a permission issue, maybe the user you are running under does
not have enough privilegies

btw, you should use TcpClient instead of Socket, unless you are planning to
use some low level functions.

Cheers,
 
Boris said:
I am trying to develop C# ftp client to upload files to remote host.
Whenever, I execute System.Net.Sockets.Socket.Connect method, .Net Framework
raises the following exception

Request for the permission of type System.Net.SocketPermission, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.

Why does this happen?

Presumably because the machine running the code hasn't given the
assembly the required level of trust.
 
Boris,

Quite simply, you don't have permission for it to run. Is the code that
this is running from being downloaded from the web, or from a shared drive?
If that is the case, then the default settings would prevent you from
accessing the Socket class.

Hope this helps.
 
Hi Ignacio,

Thanks for the response. You are right. I was running it from the network
share, and as soon as I ran it on local machine, it started working.

I am trying to implement FTP client to perform the following tasks

1) Login to remote UNIX server
2) Create appropriate directory, if not already exists
3) Upload the file into the directory
4) Delete file from the directory

Would TcpClient provide me with this functionality? Do you have any code
examples?

Thanks,
-Boris
 
Boris,

The TcpClient will only help you in connecting to the FTP server, it
will not help you with issuing the commands for the FTP. You still have to
do that yourself.

However, in .NET 2.0, there is an FtpWebRequest class, which could make
much of it easier (if you can use the beta, and roll out after the release).

Hope this helps.
 
Hi,

Thanks for the response. You are right. I was running it from the network
share, and as soon as I ran it on local machine, it started working.

Good to know !
Would TcpClient provide me with this functionality? Do you have any code
examples?

TcpClient is a easier way to handle TCP connection, nothing else, you still
have to implement the ftp protocol.

I dont have any code unfortunally, but I'm very sure that if you look into
the archives or online somewhere you will find either a component ready to
be used or an example of how to implement it.

cheers,
 
Back
Top