I have created FTPwebRequest to write a file from one of my Windows 2003 share hosting account to one of my Linux hosting account.
This is the code, I use to upload the file between servers (domains)
Public Sub uploadFileUsingFTP(ByVal CompleteFTPPath As String, ByVal CompleteLocalPath As String, Optional ByVal UName As String = "UserName", Optional ByVal PWD As String = "Password")
Dim reqObj As FtpWebRequest = WebRequest.Create(CompleteFTPPath)
reqObj.Method = WebRequestMethods.Ftp.UploadFile
reqObj.Credentials = New NetworkCredential(UName, PWD)
Dim streamObj As FileStream = File.OpenRead(CompleteLocalPath)
Dim buffer(streamObj.Length) As Byte
streamObj.Read(buffer, 0, buffer.Length)
streamObj.Close()
streamObj = Nothing
reqObj.GetRequestStream().Write(buffer, 0, buffer.Length)
reqObj = Nothing
End Sub
Then, the usage is,
uploadFileUsingFTP("ftp://ipaddress/myReal.kml", Server.MapPath("myReal.kml"))
now, this works perfect in my local server. When i upload it to Godaddy windows shared hosting account, I get an 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.
On Stack Trace:
[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 myCDN_genKML.uploadFileUsingFTP(String CompleteFTPPath, String CompleteLocalPath, String UName, String PWD) +12 myCDN_genKML.btnAdd_Click(Object sender, EventArgs e) +1313 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.mycdn_genkml_aspx.ProcessRequest(HttpContext context) +37 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
I need to sort this issue quickly... Thanks for all.