Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Upload File via FTP using VB.Net and Receiving "Not Logged In" Error??

742 views
Skip to first unread message

TC

unread,
Jul 29, 2008, 8:10:12 AM7/29/08
to
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


kimiraikkonen

unread,
Jul 29, 2008, 2:32:51 PM7/29/08
to

You can use My namepsace to upload to FTP server also by passing
credentials if required in the same code syntax:

"My.Computer.Network.UploadFile" method
http://msdn.microsoft.com/en-us/library/dfkdh7eb.aspx

Hope this helps,

Onur Güzel

Steve

unread,
Jul 29, 2008, 3:09:49 PM7/29/08
to

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_file),
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

TC

unread,
Jul 29, 2008, 8:36:20 PM7/29/08
to
Hey Steve,

When I try to get the stream, it fails with this error:

The remote server returned an error: (550) File unavailable (e.g., file not
found, no access).

Any ideas?

I'm wondering if the URL I was given is the culprit. It is:

ftp://myserverurl.com/../companyname/Incoming/Orders/

Would the "/../" cause problems?

Thanks,

Todd


"Steve" <sith...@gmail.com> wrote in message
news:c356434a-2985-4f68...@p10g2000prf.googlegroups.com...

TC

unread,
Jul 29, 2008, 9:22:58 PM7/29/08
to
Got it to work!

Turns out there was a problem with the URL that I was given. Once I had the
appropriate syntax, I was OK.

By the way, is there any reason one would use:

My.Computer.Network.UploadFile

vs.

the more verbose FtpWebRequest?

It seems that the My.Computer.Network.UploadFile method is very concise and
elegant. However, if more control is required, the latter may be a better
choice. But if all one really needs to do is upload, wouldn't the first be
a better choice?

Thanks,

Todd


"TC" <getmye...@yahoo.com> wrote in message
news:OQiYXQX8...@TK2MSFTNGP04.phx.gbl...

Steve

unread,
Jul 30, 2008, 2:24:52 PM7/30/08
to
On Jul 29, 8:22 pm, "TC" <getmyemai...@yahoo.com> wrote:
> Got it to work!
>
> Turns out there was a problem with the URL that I was given. Once I had the
> appropriate syntax, I was OK.
>
> By the way, is there any reason one would use:
>
> My.Computer.Network.UploadFile
>
> vs.
>
> the more verbose FtpWebRequest?
>
> It seems that the My.Computer.Network.UploadFile method is very concise and
> elegant. However, if more control is required, the latter may be a better
> choice. But if all one really needs to do is upload, wouldn't the first be
> a better choice?
>
> Thanks,
>
> Todd
>
> "TC" <getmyemai...@yahoo.com> wrote in message

>
> news:OQiYXQX8...@TK2MSFTNGP04.phx.gbl...
>
> > 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 to sure about that. I have been using the FtpWebRequest
method which has been working well for me. Maybe a MSFT MVP could
help you on that one.

Glad to know if worked for you.

Steve

us...@artisansolutions.in

unread,
Nov 9, 2013, 6:11:01 AM11/9/13
to
I am working on the same. i could able to transfer small files, I get error when transfering 1gb or more than that "OutOfMemory Exception"

Can any 1 suggest in this pls

My code is

Dim clsRequest As System.Net.FtpWebRequest = _
DirectCast(System.Net.WebRequest.Create(ftpuri), System.Net.FtpWebRequest)
clsRequest.Credentials = New System.Net.NetworkCredential(username, password)
Try
clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile

' read in file...
Dim bFile() As Byte = System.IO.File.ReadAllBytes(LocalFilePath)

' upload file...
Dim clsStream As System.IO.Stream = clsRequest.GetRequestStream()
clsStream.Write(bFile, 0, bFile.Length)
clsStream.Close()
clsStream.Dispose()

Catch ex As Exception

MsgBox(ex.ToString)

End Try
0 new messages