B
bob
Here i'm using this code to upload a local file to my ftp server on te web
It's work fine on my PC but when i publish. I have an error "cannot find
local file"
Here's the code :
'Get FTP web resquest object.
ftpWR = CType(FtpWebRequest.Create(New Uri("ftp://" +
System.Configuration.ConfigurationManager.AppSettings("ftpServer").ToString()
+ "/" + uploadFile.FileName)), FtpWebRequest)
ftpWR.UseBinary = True
ftpWR.Method = WebRequestMethods.Ftp.UploadFile
ftpWR.Credentials = New
NetworkCredential(System.Configuration.ConfigurationManager.AppSettings("ftpUserName").ToString(),
System.Configuration.ConfigurationManager.AppSettings("ftpPassword").ToString())
'Get physical file
Dim fi As FileInfo = New
FileInfo(UploadFile.PostedFile.FileName)
Dim contents As Byte() = New Byte(fi.Length) {}
'Read file
Dim fs As FileStream = fi.OpenRead()
fs.Read(contents, 0, fi.Length)
fs.Close()
'Write file contents to FTP server
Dim rs As Stream = ftpWR.GetRequestStream()
rs.Write(contents, 0, fi.Length)
rs.Close()
ftpWP = ftpWR.GetResponse()
Need help!
It's work fine on my PC but when i publish. I have an error "cannot find
local file"
Here's the code :
'Get FTP web resquest object.
ftpWR = CType(FtpWebRequest.Create(New Uri("ftp://" +
System.Configuration.ConfigurationManager.AppSettings("ftpServer").ToString()
+ "/" + uploadFile.FileName)), FtpWebRequest)
ftpWR.UseBinary = True
ftpWR.Method = WebRequestMethods.Ftp.UploadFile
ftpWR.Credentials = New
NetworkCredential(System.Configuration.ConfigurationManager.AppSettings("ftpUserName").ToString(),
System.Configuration.ConfigurationManager.AppSettings("ftpPassword").ToString())
'Get physical file
Dim fi As FileInfo = New
FileInfo(UploadFile.PostedFile.FileName)
Dim contents As Byte() = New Byte(fi.Length) {}
'Read file
Dim fs As FileStream = fi.OpenRead()
fs.Read(contents, 0, fi.Length)
fs.Close()
'Write file contents to FTP server
Dim rs As Stream = ftpWR.GetRequestStream()
rs.Write(contents, 0, fi.Length)
rs.Close()
ftpWP = ftpWR.GetResponse()
Need help!