?
Solved

.NET FTP which is allowed on Medium Security Settings

Posted on 2014-02-21
3
Medium Priority
?
393 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 1500 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

RHCE - Red Hat OpenStack Prep Course

This course will provide in-depth training so that students who currently hold the EX200 & EX210 certifications can sit for the EX310 exam. Students will learn how to deploy & manage a full Red Hat environment with Ceph block storage, & integrate Ceph into other OpenStack service

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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 tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

762 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