TPLLimited
asked on
.NET FTP which is allowed on Medium Security Settings
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:
GoDaddy uses Medium trust settings (you can not change this as I have tried with them).
and it keeps throwing the following error:
Is there a better way of processing FTP on a medium trust level?
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
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=b77a5c56193 4e089' failed.
Source Error:
Line 180:
Line 181: ' Try
Line 182: Dim request As FtpWebRequest = DirectCast(FtpWebRequest.Create(FTPA ddress & "/" & 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=b77a5c56193 4e089' failed.]
System.Security.CodeAccessSecurityEn gine.Check (Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
System.Security.CodeAccessPermission .Demand() +58
System.Net.FtpWebRequest..ctor(Uri uri) +161
System.Net.FtpWebRequestCreator.Crea te(Uri uri) +24
System.Net.WebRequest.Create(Uri requestUri, Boolean useUriBase) +216
System.Net.WebRequest.Create(String requestUriString) +44
Datafeed.uploadFile(StringFTPAddress, String filePath, String username, String password) in [MY SERVER FILEPATH]
Datafeed.test_Click(Objectsender, EventArgs e) in [MY SERVER FILEPATH]
System.Web.UI.WebControls.Button.OnC lick(Event Args e) +111
System.Web.UI.WebControls.Button.Rai sePostBack Event(Stri ng eventArgument) +110
System.Web.UI.WebControls.Button.Sys tem.Web.UI .IPostBack EventHandl er.RaisePo stBackEven t(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEven t(IPostBac kEventHand ler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEven t(NameValu eCollectio n postData) +36
System.Web.UI.Page.ProcessRequestMai n(Boolean includeStagesBeforeAsyncPo int, Boolean includeStagesAfterAsyncPoi nt) +6785
System.Web.UI.Page.ProcessRequest(Bo olean includeStagesBeforeAsyncPo int, Boolean includeStagesAfterAsyncPoi nt) +242
System.Web.UI.Page.ProcessRequest() +80
System.Web.UI.Page.ProcessRequestWit hNoAssert( HttpContex t context) +21
System.Web.UI.Page.ProcessRequest(Ht tpContext context) +49
ASP.datafeed_aspx.ProcessRequest(Htt pContext context) +37
System.Web.CallHandlerExecutionStep. System.Web .HttpAppli cation.IEx ecutionSte p.Execute( ) +181
System.Web.HttpApplication.ExecuteSt ep(IExecut ionStep step, Boolean& completedSynchronously) +75
Is there a better way of processing FTP on a medium trust level?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
ASKER
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