Solved

.NET FTP which is allowed on Medium Security Settings

Posted on 2014-02-21
3
350 Views
Last Modified: 2014-03-19
Hi

I currently use GoDaddy for Hosting and am trying to upload a file to another website (customer of ours) however GoDaddy keeps throwing a security exception.

The FTP code I am using is as follows:

Private Sub uploadFile(ByVal FTPAddress As String, ByVal filePath As String, ByVal username As String, ByVal password As String) 'Create FTP request

        Try
            Dim request As FtpWebRequest = DirectCast(FtpWebRequest.Create(FTPAddress & "/" & TLfilename), FtpWebRequest)

            request.Method = WebRequestMethods.Ftp.UploadFile
            request.Credentials = New NetworkCredential(username, password)
            request.UsePassive = True
            request.UseBinary = True
            request.KeepAlive = False

            Dim buffer As Byte() = Nothing
            'Load the file
            Using stream As FileStream = File.OpenRead(filePath)
                buffer = New Byte(CInt(stream.Length - 1)) {}
                stream.Read(buffer, 0, buffer.Length)
            End Using

            'Upload file
            Using reqStream As Stream = request.GetRequestStream()
                reqStream.Write(buffer, 0, buffer.Length)
            End Using

            Response.Write("Uploaded Sucessfully")
        Catch
            Response.Write("Failed to Upload")
        End Try
    End Sub

Open in new window


GoDaddy uses Medium trust settings (you can not change this as I have tried with them).

and it keeps throwing the following error:


Security Exception

Description: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Source Error:


Line 180:
Line 181:        '  Try
Line 182:        Dim request As FtpWebRequest = DirectCast(FtpWebRequest.Create(FTPAddress & "/" & TLfilename), FtpWebRequest)
Line 183:
Line 184:        request.Method = WebRequestMethods.Ftp.UploadFile


[SecurityException: Request for the permission of type 'System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
   System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
   System.Security.CodeAccessPermission.Demand() +58
   System.Net.FtpWebRequest..ctor(Uri uri) +161
   System.Net.FtpWebRequestCreator.Create(Uri uri) +24
   System.Net.WebRequest.Create(Uri requestUri, Boolean useUriBase) +216
   System.Net.WebRequest.Create(String requestUriString) +44
   Datafeed.uploadFile(String FTPAddress, String filePath, String username, String password) in [MY SERVER FILEPATH]
   Datafeed.test_Click(Object sender, EventArgs e) in [MY SERVER FILEPATH]
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6785
   System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +242
   System.Web.UI.Page.ProcessRequest() +80
   System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
   System.Web.UI.Page.ProcessRequest(HttpContext context) +49
   ASP.datafeed_aspx.ProcessRequest(HttpContext context) +37
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75



Is there a better way of processing FTP on a medium trust level?
0
Comment
Question by:TPLLimited
3 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 39876922
This may not be the answer you are looking for but another user had similar problem in 2009 and ended up moving to DiscountASP.
0
 

Author Comment

by:TPLLimited
ID: 39876964
Thanks for the reply - unfortunately been with them for 6 months and paid for 2 years worth of hosting.

Oh well lesson learned I suppose.

Can I ask have you had any problems with DiscountASP? I don't see their up-time listed anywhere
0
 
LVL 16

Expert Comment

by:AlexPace
ID: 39877009
What if you use an FTP client on your own network as a go-between?  So you download the file from your godaddy hosted FTP server to a machine on your office network and then upload the file to the customer's server from your machine?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Loop not working 29 47
Syntax error 9 45
SQL syntax in VB.net 5 27
Pagebreak issue while printing the aspx page 3 11
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now