On Jul 29, 7:10 am, "TC" <getmyemai...@yahoo.comwrote:
Hey All,
I'm trying to upload files via FTP and I'm using FtpWebRequest and
WebClient.
Unfortunately, I'm receiving a "Not Logged In" error.
I know that others have seen this as I've seen postings but I haven't seen
any clear resolution.
Does anyone have a code snippet that works?
Can someone please advise?
Thanks,
TC
I'm not sure if this is what you are looking for, but this is how I am
uploading a file to my ftp site.
'Variables
Dim local_file As String = path & filename
Dim remote_file As String = ftpsite & filename
Dim cls_request As System.Net.FtpWebRequest =
DirectCast(System.Net.WebRequest.Create(remote_fil e),
System.Net.FtpWebRequest)
Dim user_name As String = user
Dim password As String = password
'Establish credentials for logging into ftp site
cls_request.Credentials = New
System.Net.NetworkCredential(user_name, password)
'Set properties
cls_request.KeepAlive = False
cls_request.Proxy = Nothing
cls_request.Method =
System.Net.WebRequestMethods.Ftp.UploadFile
cls_request.UseBinary = True
'Read in the file
Dim b_file() As Byte = System.IO.File.ReadAllBytes(local_file)
'Upload the file
Dim cls_stream As System.IO.Stream =
cls_request.GetRequestStream()
cls_stream.Write(b_file, 0, b_file.Length)
cls_stream.Close()
cls_stream.Dispose()
This does overwrite files if they already exist.
Hope this helps,
Steve