I'm having a hard time with this thing. Which file is it referring to? The file it's going to upload to the remote server? Or, is the the path to where it's supposed to write the file on the remote server? The files that are supposed to be transferred
to a remote server are at the moment sitting on the root of my site. Here's the error:
[WebException: The remote server returned an error: (550) File unavailable (e.g., file not found, no access).] System.Net.FtpWebRequest.SyncRequestCallback(Object obj) +321 System.Net.FtpWebRequest.RequestCallback(Object obj) +19 System.Net.CommandStream.Abort(Exception e) +163 System.Net.FtpWebRequest.FinishRequestStage(RequestStage stage) +453 System.Net.FtpWebRequest.GetRequestStream() +880 upload2.btnUploadFile_Click(Object sender, EventArgs e) +140 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746
Heres the code:
Imports System.Net
Imports System.IO
Partial Class upload2
Inherits System.Web.UI.Page
Protected Sub btnUploadFile_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim myFtpWebRequest As FtpWebRequest
Dim myFtpWebResponse As FtpWebResponse
Dim myStreamWriter As StreamWriter
myFtpWebRequest = WebRequest.Create("ftp://mortgage-pros.com/links/ftp.txt")
Dim litresponse As String
myFtpWebRequest.Credentials = New NetworkCredential("", "") 'removed info
myFtpWebRequest.Method = WebRequestMethods.Ftp.UploadFile
myFtpWebRequest.UseBinary = True
myStreamWriter = New StreamWriter(myFtpWebRequest.GetRequestStream())
myStreamWriter.Write(New StreamReader(Server.MapPath("~" + "/ftp.txt")).ReadToEnd) 'this is the path of the file being moved to another server
myStreamWriter.Close()
myFtpWebResponse = myFtpWebRequest.GetResponse()
litResponse = myFtpWebResponse.StatusDescription
myFtpWebResponse.Close()
End Sub
Protected Sub btnDownloadFile_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim myFtpWebRequest As FtpWebRequest
Dim myFtpWebResponse As FtpWebResponse
Dim myStreamWriter As StreamWriter
Dim litresponse As String
myFtpWebRequest = WebRequest.Create("ftp://ftp_server_name/filename.ext")
'myFtpWebRequest.Credentials = New NetworkCredential("username", "password")
myFtpWebRequest.Method = WebRequestMethods.Ftp.DownloadFile
myFtpWebRequest.UseBinary = True
myFtpWebResponse = myFtpWebRequest.GetResponse()
myStreamWriter = New StreamWriter(Server.MapPath("filename.ext"))
myStreamWriter.Write(New StreamReader(myFtpWebResponse.GetResponseStream()).ReadToEnd)
myStreamWriter.Close()
litResponse = myFtpWebResponse.StatusDescription
myFtpWebResponse.Close()
End Sub
Protected Sub btnDeleteFile_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim myFtpWebRequest As FtpWebRequest
Dim myFtpWebResponse As FtpWebResponse
Dim litresponse As String
myFtpWebRequest = WebRequest.Create("ftp://ftp_server_name/filename.ext")
'myFtpWebRequest.Credentials = New NetworkCredential("username", "password")
myFtpWebRequest.Method = WebRequestMethods.Ftp.DeleteFile
myFtpWebResponse = myFtpWebRequest.GetResponse()
litresponse = myFtpWebResponse.StatusDescription
myFtpWebResponse.Close()
End Sub
End Class
sking
Member
508 Points
1026 Posts
File unavailable (e.g., file not found, no access).
Aug 24, 2008 04:19 AM|LINK
I'm having a hard time with this thing. Which file is it referring to? The file it's going to upload to the remote server? Or, is the the path to where it's supposed to write the file on the remote server? The files that are supposed to be transferred to a remote server are at the moment sitting on the root of my site. Here's the error:
Heres the code:
Imports System.Net Imports System.IO Partial Class upload2 Inherits System.Web.UI.Page Protected Sub btnUploadFile_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim myFtpWebRequest As FtpWebRequest Dim myFtpWebResponse As FtpWebResponse Dim myStreamWriter As StreamWriter myFtpWebRequest = WebRequest.Create("ftp://mortgage-pros.com/links/ftp.txt") Dim litresponse As String myFtpWebRequest.Credentials = New NetworkCredential("", "") 'removed info myFtpWebRequest.Method = WebRequestMethods.Ftp.UploadFile myFtpWebRequest.UseBinary = True myStreamWriter = New StreamWriter(myFtpWebRequest.GetRequestStream()) myStreamWriter.Write(New StreamReader(Server.MapPath("~" + "/ftp.txt")).ReadToEnd) 'this is the path of the file being moved to another server myStreamWriter.Close() myFtpWebResponse = myFtpWebRequest.GetResponse() litResponse = myFtpWebResponse.StatusDescription myFtpWebResponse.Close() End Sub Protected Sub btnDownloadFile_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim myFtpWebRequest As FtpWebRequest Dim myFtpWebResponse As FtpWebResponse Dim myStreamWriter As StreamWriter Dim litresponse As String myFtpWebRequest = WebRequest.Create("ftp://ftp_server_name/filename.ext") 'myFtpWebRequest.Credentials = New NetworkCredential("username", "password") myFtpWebRequest.Method = WebRequestMethods.Ftp.DownloadFile myFtpWebRequest.UseBinary = True myFtpWebResponse = myFtpWebRequest.GetResponse() myStreamWriter = New StreamWriter(Server.MapPath("filename.ext")) myStreamWriter.Write(New StreamReader(myFtpWebResponse.GetResponseStream()).ReadToEnd) myStreamWriter.Close() litResponse = myFtpWebResponse.StatusDescription myFtpWebResponse.Close() End Sub Protected Sub btnDeleteFile_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim myFtpWebRequest As FtpWebRequest Dim myFtpWebResponse As FtpWebResponse Dim litresponse As String myFtpWebRequest = WebRequest.Create("ftp://ftp_server_name/filename.ext") 'myFtpWebRequest.Credentials = New NetworkCredential("username", "password") myFtpWebRequest.Method = WebRequestMethods.Ftp.DeleteFile myFtpWebResponse = myFtpWebRequest.GetResponse() litresponse = myFtpWebResponse.StatusDescription myFtpWebResponse.Close() End Sub End ClassSEO Software Tool | Link Exchange