MeghanOBrien
asked on
ASP.NET using VB FTP Upload
I wrote a function that uploads images to my web server. The function works fine when I execute the code, but when I post the page and try to use the function through the website, I receive this error:
System.IO.FileNotFoundExce ption: Could not find file 'c:\windows\system32\inets rv\myimage name.jpg'. File name: 'c:\windows\system32\inets rv\myimage name.jpg' at System.IO.__Error.WinIOErr or(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init( String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor (String path, FileMode mode, FileAccess access, FileShare share) at System.IO.File.ReadAllByte s(String path) at SiteFTPFunction.FTPUpload( String FTPDestination, String LocalCopy, String strUserName, String strFileName) in C:\Domains\mywebsite.net\w wwroot\App _Code\Site FTPFunctio n.vb:line 24
System.IO.FileNotFoundExce
Public Function FTPUpload(ByVal FTPDestination As String, ByVal LocalCopy As String, ByVal strUserName As String, ByVal strFileName As String) As String
Dim strResult As String = ""
Dim filePath As String = ""
Dim newFileName As String = ""
Try
Dim clsRequest As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create(ftpDirectory & FTPDestination), System.Net.FtpWebRequest)
clsRequest.Credentials = New System.Net.NetworkCredential(ftpUserName, ftpPassword)
clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile
Dim bFile() As Byte = System.IO.File.ReadAllBytes(LocalCopy)
Dim clsStream As System.IO.Stream = clsRequest.GetRequestStream()
clsStream.Write(bFile, 0, bFile.Length)
clsStream.Dispose()
clsStream.Close()
strResult = RecordFileUpload(strUserName, strFileName, LocalCopy, FTPDestination)
strResult = "Success"
Catch ex As Exception
strResult = "Error"
strResult = ex.ToString
End Try
Return strResult
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Bu this will not work on server.
You are using FTP to upload the file. You cannot assume that file you are accessing will be on the server.
Try changing the path