Solved

.NET FTP which is allowed on Medium Security Settings

Posted on 2014-02-21
3
341 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

15 Experts available now in Live!

Get 1:1 Help Now