Connecting Tech Pros Worldwide Forums | Help | Site Map

connect to FTP server

CSharpguy
Guest
 
Posts: n/a
#1: Apr 28 '06
I need to upload a file to an FTP server, can someone point me to some code
that connects to an FTP server and uploads a file?



CSharpguy
Guest
 
Posts: n/a
#2: Apr 28 '06

re: connect to FTP server


where? what link is it under? i went to all 3 and didn't see anything on FTP

"Swanand Mokashi" wrote:
[color=blue]
> Here is a class I wrote for FTP connections. See if it is useful to you
>
> --
> Swanand Mokashi
> Microsoft Certified Solution Developer (.NET) - Early Achiever
> Microsoft Certified Application Developer (.NET)
>
> http://www.dotnetgenerics.com/
> DotNetGenerics.com -- anything and everything about Microsoft .NET
> technology ...
>
> http://www.swanandmokashi.com/
> http://www.swanandmokashi.com/HomePage/WebServices/
> Home of the Stock Quotes, Quote of the day and Horoscope web services
>
>
> "CSharpguy" <CSharpguy@discussions.microsoft.com> wrote in message
> news:456D9AFD-5B3C-456A-82E4-72EE27D26D8D@microsoft.com...[color=green]
> >I need to upload a file to an FTP server, can someone point me to some code
> > that connects to an FTP server and uploads a file?
> >
> >[/color]
>
>
>[/color]
Juan T. Llibre
Guest
 
Posts: n/a
#3: Apr 28 '06

re: connect to FTP server


Here's a full-featured, free, FTP Client Library, written in C# :

http://www.c-sharpcorner.com/UploadF...FtpClient.aspx

It's less than 6KB in size.

Here's another example :
http://www.hotscripts.com/Detailed/40607.html



Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"CSharpguy" <CSharpguy@discussions.microsoft.com> wrote in message
news:456D9AFD-5B3C-456A-82E4-72EE27D26D8D@microsoft.com...[color=blue]
>I need to upload a file to an FTP server, can someone point me to some code
> that connects to an FTP server and uploads a file?
>
>[/color]


Juan T. Llibre
Guest
 
Posts: n/a
#4: Apr 28 '06

re: connect to FTP server


It's in a text file, as an attachment to his post.




Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"CSharpguy" <CSharpguy@discussions.microsoft.com> wrote in message
news:7740508A-7B24-4512-81A8-DE581415828D@microsoft.com...[color=blue]
> where? what link is it under? i went to all 3 and didn't see anything on FTP
>
> "Swanand Mokashi" wrote:
>[color=green]
>> Here is a class I wrote for FTP connections. See if it is useful to you
>>
>> --
>> Swanand Mokashi
>> Microsoft Certified Solution Developer (.NET) - Early Achiever
>> Microsoft Certified Application Developer (.NET)
>>
>> http://www.dotnetgenerics.com/
>> DotNetGenerics.com -- anything and everything about Microsoft .NET
>> technology ...
>>
>> http://www.swanandmokashi.com/
>> http://www.swanandmokashi.com/HomePage/WebServices/
>> Home of the Stock Quotes, Quote of the day and Horoscope web services
>>
>>
>> "CSharpguy" <CSharpguy@discussions.microsoft.com> wrote in message
>> news:456D9AFD-5B3C-456A-82E4-72EE27D26D8D@microsoft.com...[color=darkred]
>> >I need to upload a file to an FTP server, can someone point me to some code
>> > that connects to an FTP server and uploads a file?
>> >
>> >[/color]
>>
>>
>>[/color][/color]


Swanand Mokashi
Guest
 
Posts: n/a
#5: Apr 28 '06

re: connect to FTP server


It is in the attachement.

--
Swanand Mokashi
Microsoft Certified Solution Developer (.NET) - Early Achiever
Microsoft Certified Application Developer (.NET)

http://www.dotnetgenerics.com/
DotNetGenerics.com -- anything and everything about Microsoft .NET
technology ...

http://www.swanandmokashi.com/
http://www.swanandmokashi.com/HomePage/WebServices/
Home of the Stock Quotes, Quote of the day and Horoscope web services


"CSharpguy" <CSharpguy@discussions.microsoft.com> wrote in message
news:7740508A-7B24-4512-81A8-DE581415828D@microsoft.com...[color=blue]
> where? what link is it under? i went to all 3 and didn't see anything on
> FTP
>
> "Swanand Mokashi" wrote:
>[color=green]
>> Here is a class I wrote for FTP connections. See if it is useful to you
>>
>> --
>> Swanand Mokashi
>> Microsoft Certified Solution Developer (.NET) - Early Achiever
>> Microsoft Certified Application Developer (.NET)
>>
>> http://www.dotnetgenerics.com/
>> DotNetGenerics.com -- anything and everything about Microsoft .NET
>> technology ...
>>
>> http://www.swanandmokashi.com/
>> http://www.swanandmokashi.com/HomePage/WebServices/
>> Home of the Stock Quotes, Quote of the day and Horoscope web services
>>
>>
>> "CSharpguy" <CSharpguy@discussions.microsoft.com> wrote in message
>> news:456D9AFD-5B3C-456A-82E4-72EE27D26D8D@microsoft.com...[color=darkred]
>> >I need to upload a file to an FTP server, can someone point me to some
>> >code
>> > that connects to an FTP server and uploads a file?
>> >
>> >[/color]
>>
>>
>>[/color][/color]


Kevin Spencer
Guest
 
Posts: n/a
#6: Apr 28 '06

re: connect to FTP server


I might mention that these should be construed as examples. I had to write
an FTP client, and the Socket connection and related functionality is not
difficult at all. What *is* difficult is handling the various
network-related issues that can arise. For an FTP client to be robust, it
needs to have a lot of recovery functionality (retries, timers, etc) built
into it.

Another issue is that some of the format of the returned data, such as
directory listing and system status, is not standardized, and can be
difficult to parse.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

"Juan T. Llibre" <nomailreplies@nowhere.com> wrote in message
news:OzMOzjsaGHA.3444@TK2MSFTNGP05.phx.gbl...[color=blue]
> Here's a full-featured, free, FTP Client Library, written in C# :
>
> http://www.c-sharpcorner.com/UploadF...FtpClient.aspx
>
> It's less than 6KB in size.
>
> Here's another example :
> http://www.hotscripts.com/Detailed/40607.html
>
>
>
> Juan T. Llibre, asp.net MVP
> aspnetfaq.com : http://www.aspnetfaq.com/
> asp.net faq : http://asp.net.do/faq/
> foros de asp.net, en español : http://asp.net.do/foros/
> ===================================
> "CSharpguy" <CSharpguy@discussions.microsoft.com> wrote in message
> news:456D9AFD-5B3C-456A-82E4-72EE27D26D8D@microsoft.com...[color=green]
>>I need to upload a file to an FTP server, can someone point me to some
>>code
>> that connects to an FTP server and uploads a file?
>>
>>[/color]
>
>[/color]


Juan T. Llibre
Guest
 
Posts: n/a
#7: Apr 28 '06

re: connect to FTP server


Good points, Kevin.




Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Kevin Spencer" <kevin@DIESPAMMERSDIEtakempis.com> wrote in message
news:eUcNu2saGHA.3976@TK2MSFTNGP02.phx.gbl...[color=blue]
>I might mention that these should be construed as examples. I had to write an FTP client, and the
>Socket connection and related functionality is not difficult at all. What *is* difficult is
>handling the various network-related issues that can arise. For an FTP client to be robust, it
>needs to have a lot of recovery functionality (retries, timers, etc) built into it.
>
> Another issue is that some of the format of the returned data, such as directory listing and
> system status, is not standardized, and can be difficult to parse.
>
> --
> HTH,
>
> Kevin Spencer
> Microsoft MVP
> Professional Numbskull
>
> Hard work is a medication for which
> there is no placebo.
>
> "Juan T. Llibre" <nomailreplies@nowhere.com> wrote in message
> news:OzMOzjsaGHA.3444@TK2MSFTNGP05.phx.gbl...[color=green]
>> Here's a full-featured, free, FTP Client Library, written in C# :
>>
>> http://www.c-sharpcorner.com/UploadF...FtpClient.aspx
>>
>> It's less than 6KB in size.
>>
>> Here's another example :
>> http://www.hotscripts.com/Detailed/40607.html
>>
>>
>>
>> Juan T. Llibre, asp.net MVP
>> aspnetfaq.com : http://www.aspnetfaq.com/
>> asp.net faq : http://asp.net.do/faq/
>> foros de asp.net, en español : http://asp.net.do/foros/
>> ===================================
>> "CSharpguy" <CSharpguy@discussions.microsoft.com> wrote in message
>> news:456D9AFD-5B3C-456A-82E4-72EE27D26D8D@microsoft.com...[color=darkred]
>>>I need to upload a file to an FTP server, can someone point me to some code
>>> that connects to an FTP server and uploads a file?
>>>
>>>[/color]
>>
>>[/color]
>
>[/color]


CSharpguy
Guest
 
Posts: n/a
#8: Apr 28 '06

re: connect to FTP server


I'll consider that as well, but all I need to do realy is upload the file
then check to confirm it got there.

"Kevin Spencer" wrote:
[color=blue]
> I might mention that these should be construed as examples. I had to write
> an FTP client, and the Socket connection and related functionality is not
> difficult at all. What *is* difficult is handling the various
> network-related issues that can arise. For an FTP client to be robust, it
> needs to have a lot of recovery functionality (retries, timers, etc) built
> into it.
>
> Another issue is that some of the format of the returned data, such as
> directory listing and system status, is not standardized, and can be
> difficult to parse.
>
> --
> HTH,
>
> Kevin Spencer
> Microsoft MVP
> Professional Numbskull
>
> Hard work is a medication for which
> there is no placebo.
>
> "Juan T. Llibre" <nomailreplies@nowhere.com> wrote in message
> news:OzMOzjsaGHA.3444@TK2MSFTNGP05.phx.gbl...[color=green]
> > Here's a full-featured, free, FTP Client Library, written in C# :
> >
> > http://www.c-sharpcorner.com/UploadF...FtpClient.aspx
> >
> > It's less than 6KB in size.
> >
> > Here's another example :
> > http://www.hotscripts.com/Detailed/40607.html
> >
> >
> >
> > Juan T. Llibre, asp.net MVP
> > aspnetfaq.com : http://www.aspnetfaq.com/
> > asp.net faq : http://asp.net.do/faq/
> > foros de asp.net, en español : http://asp.net.do/foros/
> > ===================================
> > "CSharpguy" <CSharpguy@discussions.microsoft.com> wrote in message
> > news:456D9AFD-5B3C-456A-82E4-72EE27D26D8D@microsoft.com...[color=darkred]
> >>I need to upload a file to an FTP server, can someone point me to some
> >>code
> >> that connects to an FTP server and uploads a file?
> >>
> >>[/color]
> >
> >[/color]
>
>
>[/color]
Swanand Mokashi
Guest
 
Posts: n/a
#9: Apr 28 '06

re: connect to FTP server


The sample code I attached should let you do that.

--
Swanand Mokashi
Microsoft Certified Solution Developer (.NET) - Early Achiever
Microsoft Certified Application Developer (.NET)

http://www.dotnetgenerics.com/
DotNetGenerics.com -- anything and everything about Microsoft .NET
technology ...

http://www.swanandmokashi.com/
http://www.swanandmokashi.com/HomePage/WebServices/
Home of the Stock Quotes, Quote of the day and Horoscope web services


"CSharpguy" <CSharpguy@discussions.microsoft.com> wrote in message
news:CE5BE3DA-5716-46EF-B01D-522A2085C38C@microsoft.com...[color=blue]
> I'll consider that as well, but all I need to do realy is upload the file
> then check to confirm it got there.
>
> "Kevin Spencer" wrote:
>[color=green]
>> I might mention that these should be construed as examples. I had to
>> write
>> an FTP client, and the Socket connection and related functionality is not
>> difficult at all. What *is* difficult is handling the various
>> network-related issues that can arise. For an FTP client to be robust, it
>> needs to have a lot of recovery functionality (retries, timers, etc)
>> built
>> into it.
>>
>> Another issue is that some of the format of the returned data, such as
>> directory listing and system status, is not standardized, and can be
>> difficult to parse.
>>
>> --
>> HTH,
>>
>> Kevin Spencer
>> Microsoft MVP
>> Professional Numbskull
>>
>> Hard work is a medication for which
>> there is no placebo.
>>
>> "Juan T. Llibre" <nomailreplies@nowhere.com> wrote in message
>> news:OzMOzjsaGHA.3444@TK2MSFTNGP05.phx.gbl...[color=darkred]
>> > Here's a full-featured, free, FTP Client Library, written in C# :
>> >
>> > http://www.c-sharpcorner.com/UploadF...FtpClient.aspx
>> >
>> > It's less than 6KB in size.
>> >
>> > Here's another example :
>> > http://www.hotscripts.com/Detailed/40607.html
>> >
>> >
>> >
>> > Juan T. Llibre, asp.net MVP
>> > aspnetfaq.com : http://www.aspnetfaq.com/
>> > asp.net faq : http://asp.net.do/faq/
>> > foros de asp.net, en español : http://asp.net.do/foros/
>> > ===================================
>> > "CSharpguy" <CSharpguy@discussions.microsoft.com> wrote in message
>> > news:456D9AFD-5B3C-456A-82E4-72EE27D26D8D@microsoft.com...
>> >>I need to upload a file to an FTP server, can someone point me to some
>> >>code
>> >> that connects to an FTP server and uploads a file?
>> >>
>> >>
>> >
>> >[/color]
>>
>>
>>[/color][/color]


Mark Rae
Guest
 
Posts: n/a
#10: Apr 28 '06

re: connect to FTP server


"CSharpguy" <CSharpguy@discussions.microsoft.com> wrote in message
news:7740508A-7B24-4512-81A8-DE581415828D@microsoft.com...
[color=blue]
> where? what link is it under? i went to all 3 and didn't see anything on
> FTP[/color]

It was in an attachment to the reply. Your newsreader is probably set to
remove all attachments to posts - mine certainly is...


CSharpguy
Guest
 
Posts: n/a
#11: Apr 28 '06

re: connect to FTP server


I'm using the code and I'm getting 'access denie to file c:\ftptest.txt"
file, or I get False returned. Do i need to do anything on my box other then
the code? I'm logged into the FTP server (via a gui) to see if my file is
getting uploaded and its not, also when I try and download a file I get
"access denied to c:\windows\system32\ftptest.txt"

whats missing

"Swanand Mokashi" wrote:
[color=blue]
> The sample code I attached should let you do that.
>
> --
> Swanand Mokashi
> Microsoft Certified Solution Developer (.NET) - Early Achiever
> Microsoft Certified Application Developer (.NET)
>
> http://www.dotnetgenerics.com/
> DotNetGenerics.com -- anything and everything about Microsoft .NET
> technology ...
>
> http://www.swanandmokashi.com/
> http://www.swanandmokashi.com/HomePage/WebServices/
> Home of the Stock Quotes, Quote of the day and Horoscope web services
>
>
> "CSharpguy" <CSharpguy@discussions.microsoft.com> wrote in message
> news:CE5BE3DA-5716-46EF-B01D-522A2085C38C@microsoft.com...[color=green]
> > I'll consider that as well, but all I need to do realy is upload the file
> > then check to confirm it got there.
> >
> > "Kevin Spencer" wrote:
> >[color=darkred]
> >> I might mention that these should be construed as examples. I had to
> >> write
> >> an FTP client, and the Socket connection and related functionality is not
> >> difficult at all. What *is* difficult is handling the various
> >> network-related issues that can arise. For an FTP client to be robust, it
> >> needs to have a lot of recovery functionality (retries, timers, etc)
> >> built
> >> into it.
> >>
> >> Another issue is that some of the format of the returned data, such as
> >> directory listing and system status, is not standardized, and can be
> >> difficult to parse.
> >>
> >> --
> >> HTH,
> >>
> >> Kevin Spencer
> >> Microsoft MVP
> >> Professional Numbskull
> >>
> >> Hard work is a medication for which
> >> there is no placebo.
> >>
> >> "Juan T. Llibre" <nomailreplies@nowhere.com> wrote in message
> >> news:OzMOzjsaGHA.3444@TK2MSFTNGP05.phx.gbl...
> >> > Here's a full-featured, free, FTP Client Library, written in C# :
> >> >
> >> > http://www.c-sharpcorner.com/UploadF...FtpClient.aspx
> >> >
> >> > It's less than 6KB in size.
> >> >
> >> > Here's another example :
> >> > http://www.hotscripts.com/Detailed/40607.html
> >> >
> >> >
> >> >
> >> > Juan T. Llibre, asp.net MVP
> >> > aspnetfaq.com : http://www.aspnetfaq.com/
> >> > asp.net faq : http://asp.net.do/faq/
> >> > foros de asp.net, en español : http://asp.net.do/foros/
> >> > ===================================
> >> > "CSharpguy" <CSharpguy@discussions.microsoft.com> wrote in message
> >> > news:456D9AFD-5B3C-456A-82E4-72EE27D26D8D@microsoft.com...
> >> >>I need to upload a file to an FTP server, can someone point me to some
> >> >>code
> >> >> that connects to an FTP server and uploads a file?
> >> >>
> >> >>
> >> >
> >> >
> >>
> >>
> >>[/color][/color]
>
>
>[/color]
CSharpguy
Guest
 
Posts: n/a
#12: Apr 28 '06

re: connect to FTP server


I'm using this buy they way:

http://www.c-sharpcorner.com/UploadF...FtpClient.aspx

"Swanand Mokashi" wrote:
[color=blue]
> The sample code I attached should let you do that.
>
> --
> Swanand Mokashi
> Microsoft Certified Solution Developer (.NET) - Early Achiever
> Microsoft Certified Application Developer (.NET)
>
> http://www.dotnetgenerics.com/
> DotNetGenerics.com -- anything and everything about Microsoft .NET
> technology ...
>
> http://www.swanandmokashi.com/
> http://www.swanandmokashi.com/HomePage/WebServices/
> Home of the Stock Quotes, Quote of the day and Horoscope web services
>
>
> "CSharpguy" <CSharpguy@discussions.microsoft.com> wrote in message
> news:CE5BE3DA-5716-46EF-B01D-522A2085C38C@microsoft.com...[color=green]
> > I'll consider that as well, but all I need to do realy is upload the file
> > then check to confirm it got there.
> >
> > "Kevin Spencer" wrote:
> >[color=darkred]
> >> I might mention that these should be construed as examples. I had to
> >> write
> >> an FTP client, and the Socket connection and related functionality is not
> >> difficult at all. What *is* difficult is handling the various
> >> network-related issues that can arise. For an FTP client to be robust, it
> >> needs to have a lot of recovery functionality (retries, timers, etc)
> >> built
> >> into it.
> >>
> >> Another issue is that some of the format of the returned data, such as
> >> directory listing and system status, is not standardized, and can be
> >> difficult to parse.
> >>
> >> --
> >> HTH,
> >>
> >> Kevin Spencer
> >> Microsoft MVP
> >> Professional Numbskull
> >>
> >> Hard work is a medication for which
> >> there is no placebo.
> >>
> >> "Juan T. Llibre" <nomailreplies@nowhere.com> wrote in message
> >> news:OzMOzjsaGHA.3444@TK2MSFTNGP05.phx.gbl...
> >> > Here's a full-featured, free, FTP Client Library, written in C# :
> >> >
> >> > http://www.c-sharpcorner.com/UploadF...FtpClient.aspx
> >> >
> >> > It's less than 6KB in size.
> >> >
> >> > Here's another example :
> >> > http://www.hotscripts.com/Detailed/40607.html
> >> >
> >> >
> >> >
> >> > Juan T. Llibre, asp.net MVP
> >> > aspnetfaq.com : http://www.aspnetfaq.com/
> >> > asp.net faq : http://asp.net.do/faq/
> >> > foros de asp.net, en español : http://asp.net.do/foros/
> >> > ===================================
> >> > "CSharpguy" <CSharpguy@discussions.microsoft.com> wrote in message
> >> > news:456D9AFD-5B3C-456A-82E4-72EE27D26D8D@microsoft.com...
> >> >>I need to upload a file to an FTP server, can someone point me to some
> >> >>code
> >> >> that connects to an FTP server and uploads a file?
> >> >>
> >> >>
> >> >
> >> >
> >>
> >>
> >>[/color][/color]
>
>
>[/color]
Juan T. Llibre
Guest
 
Posts: n/a
#13: Apr 28 '06

re: connect to FTP server


re:[color=blue]
> when I try and download a file I get "access denied to c:\windows\system32\ftptest.txt"[/color]

You need to specify a directory which isn't security-conscious
as the destination for the uploaded files.

I'd *never* upload files to that directory.

Also, if you're getting "access denied", the account ASP.NET is running as
doesn't have enough permissions to access the file and/or directory.

Save the following code as "identity.aspx" and run the file.

identity.aspx
=========
<%@ Page Language="VB" %>
<%@ Import NameSpace = System.Security.Principal %>
<script runat="server">
Sub Page_Load()
Dim tmp As String = WindowsIdentity.GetCurrent.Name()
Label1.Text = tmp
End Sub
</script>
<html>
<head>
<title>WindowsIdentity.GetCurrent.Name()</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" Runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
======

Then, assign access permissions for the file/directory to the account which that file returns.

Remember to change the upload directory to an ad-hoc directory.
Don't use c:\windows\system32\ as your upload directory.




Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"CSharpguy" <CSharpguy@discussions.microsoft.com> wrote in message
news:FEFFF6CD-00DE-49AA-B3D6-658E88E31443@microsoft.com...[color=blue]
> I'm using the code and I'm getting 'access denie to file c:\ftptest.txt"
> file, or I get False returned. Do i need to do anything on my box other then
> the code? I'm logged into the FTP server (via a gui) to see if my file is
> getting uploaded and its not, also when I try and download a file I get
> "access denied to c:\windows\system32\ftptest.txt"
>
> whats missing
>
> "Swanand Mokashi" wrote:
>[color=green]
>> The sample code I attached should let you do that.
>>
>> --
>> Swanand Mokashi
>> Microsoft Certified Solution Developer (.NET) - Early Achiever
>> Microsoft Certified Application Developer (.NET)
>>
>> http://www.dotnetgenerics.com/
>> DotNetGenerics.com -- anything and everything about Microsoft .NET
>> technology ...
>>
>> http://www.swanandmokashi.com/
>> http://www.swanandmokashi.com/HomePage/WebServices/
>> Home of the Stock Quotes, Quote of the day and Horoscope web services
>>
>>
>> "CSharpguy" <CSharpguy@discussions.microsoft.com> wrote in message
>> news:CE5BE3DA-5716-46EF-B01D-522A2085C38C@microsoft.com...[color=darkred]
>> > I'll consider that as well, but all I need to do realy is upload the file
>> > then check to confirm it got there.
>> >
>> > "Kevin Spencer" wrote:
>> >
>> >> I might mention that these should be construed as examples. I had to
>> >> write
>> >> an FTP client, and the Socket connection and related functionality is not
>> >> difficult at all. What *is* difficult is handling the various
>> >> network-related issues that can arise. For an FTP client to be robust, it
>> >> needs to have a lot of recovery functionality (retries, timers, etc)
>> >> built
>> >> into it.
>> >>
>> >> Another issue is that some of the format of the returned data, such as
>> >> directory listing and system status, is not standardized, and can be
>> >> difficult to parse.
>> >>
>> >> --
>> >> HTH,
>> >>
>> >> Kevin Spencer
>> >> Microsoft MVP
>> >> Professional Numbskull
>> >>
>> >> Hard work is a medication for which
>> >> there is no placebo.
>> >>
>> >> "Juan T. Llibre" <nomailreplies@nowhere.com> wrote in message
>> >> news:OzMOzjsaGHA.3444@TK2MSFTNGP05.phx.gbl...
>> >> > Here's a full-featured, free, FTP Client Library, written in C# :
>> >> >
>> >> > http://www.c-sharpcorner.com/UploadF...FtpClient.aspx
>> >> >
>> >> > It's less than 6KB in size.
>> >> >
>> >> > Here's another example :
>> >> > http://www.hotscripts.com/Detailed/40607.html
>> >> >
>> >> >
>> >> >
>> >> > Juan T. Llibre, asp.net MVP
>> >> > aspnetfaq.com : http://www.aspnetfaq.com/
>> >> > asp.net faq : http://asp.net.do/faq/
>> >> > foros de asp.net, en español : http://asp.net.do/foros/
>> >> > ===================================
>> >> > "CSharpguy" <CSharpguy@discussions.microsoft.com> wrote in message
>> >> > news:456D9AFD-5B3C-456A-82E4-72EE27D26D8D@microsoft.com...
>> >> >>I need to upload a file to an FTP server, can someone point me to some
>> >> >>code
>> >> >> that connects to an FTP server and uploads a file?
>> >> >>
>> >> >>
>> >> >
>> >> >
>> >>
>> >>
>> >>[/color]
>>
>>
>>[/color][/color]


CSharpguy
Guest
 
Posts: n/a
#14: Apr 28 '06

re: connect to FTP server


I didn't specify that directory, when I was trying to pull down the file it
tried and dump it there. I have an upload directory I'm working on pulling
the files from

"Juan T. Llibre" wrote:
[color=blue]
> re:[color=green]
> > when I try and download a file I get "access denied to c:\windows\system32\ftptest.txt"[/color]
>
> You need to specify a directory which isn't security-conscious
> as the destination for the uploaded files.
>
> I'd *never* upload files to that directory.
>
> Also, if you're getting "access denied", the account ASP.NET is running as
> doesn't have enough permissions to access the file and/or directory.
>
> Save the following code as "identity.aspx" and run the file.
>
> identity.aspx
> =========
> <%@ Page Language="VB" %>
> <%@ Import NameSpace = System.Security.Principal %>
> <script runat="server">
> Sub Page_Load()
> Dim tmp As String = WindowsIdentity.GetCurrent.Name()
> Label1.Text = tmp
> End Sub
> </script>
> <html>
> <head>
> <title>WindowsIdentity.GetCurrent.Name()</title>
> </head>
> <body>
> <form id="form1" runat="server">
> <div>
> <asp:Label ID="Label1" Runat="server" Text="Label"></asp:Label>
> </div>
> </form>
> </body>
> </html>
> ======
>
> Then, assign access permissions for the file/directory to the account which that file returns.
>
> Remember to change the upload directory to an ad-hoc directory.
> Don't use c:\windows\system32\ as your upload directory.
>
>
>
>
> Juan T. Llibre, asp.net MVP
> aspnetfaq.com : http://www.aspnetfaq.com/
> asp.net faq : http://asp.net.do/faq/
> foros de asp.net, en español : http://asp.net.do/foros/
> ===================================
> "CSharpguy" <CSharpguy@discussions.microsoft.com> wrote in message
> news:FEFFF6CD-00DE-49AA-B3D6-658E88E31443@microsoft.com...[color=green]
> > I'm using the code and I'm getting 'access denie to file c:\ftptest.txt"
> > file, or I get False returned. Do i need to do anything on my box other then
> > the code? I'm logged into the FTP server (via a gui) to see if my file is
> > getting uploaded and its not, also when I try and download a file I get
> > "access denied to c:\windows\system32\ftptest.txt"
> >
> > whats missing
> >
> > "Swanand Mokashi" wrote:
> >[color=darkred]
> >> The sample code I attached should let you do that.
> >>
> >> --
> >> Swanand Mokashi
> >> Microsoft Certified Solution Developer (.NET) - Early Achiever
> >> Microsoft Certified Application Developer (.NET)
> >>
> >> http://www.dotnetgenerics.com/
> >> DotNetGenerics.com -- anything and everything about Microsoft .NET
> >> technology ...
> >>
> >> http://www.swanandmokashi.com/
> >> http://www.swanandmokashi.com/HomePage/WebServices/
> >> Home of the Stock Quotes, Quote of the day and Horoscope web services
> >>
> >>
> >> "CSharpguy" <CSharpguy@discussions.microsoft.com> wrote in message
> >> news:CE5BE3DA-5716-46EF-B01D-522A2085C38C@microsoft.com...
> >> > I'll consider that as well, but all I need to do realy is upload the file
> >> > then check to confirm it got there.
> >> >
> >> > "Kevin Spencer" wrote:
> >> >
> >> >> I might mention that these should be construed as examples. I had to
> >> >> write
> >> >> an FTP client, and the Socket connection and related functionality is not
> >> >> difficult at all. What *is* difficult is handling the various
> >> >> network-related issues that can arise. For an FTP client to be robust, it
> >> >> needs to have a lot of recovery functionality (retries, timers, etc)
> >> >> built
> >> >> into it.
> >> >>
> >> >> Another issue is that some of the format of the returned data, such as
> >> >> directory listing and system status, is not standardized, and can be
> >> >> difficult to parse.
> >> >>
> >> >> --
> >> >> HTH,
> >> >>
> >> >> Kevin Spencer
> >> >> Microsoft MVP
> >> >> Professional Numbskull
> >> >>
> >> >> Hard work is a medication for which
> >> >> there is no placebo.
> >> >>
> >> >> "Juan T. Llibre" <nomailreplies@nowhere.com> wrote in message
> >> >> news:OzMOzjsaGHA.3444@TK2MSFTNGP05.phx.gbl...
> >> >> > Here's a full-featured, free, FTP Client Library, written in C# :
> >> >> >
> >> >> > http://www.c-sharpcorner.com/UploadF...FtpClient.aspx
> >> >> >
> >> >> > It's less than 6KB in size.
> >> >> >
> >> >> > Here's another example :
> >> >> > http://www.hotscripts.com/Detailed/40607.html
> >> >> >
> >> >> >
> >> >> >
> >> >> > Juan T. Llibre, asp.net MVP
> >> >> > aspnetfaq.com : http://www.aspnetfaq.com/
> >> >> > asp.net faq : http://asp.net.do/faq/
> >> >> > foros de asp.net, en español : http://asp.net.do/foros/
> >> >> > ===================================
> >> >> > "CSharpguy" <CSharpguy@discussions.microsoft.com> wrote in message
> >> >> > news:456D9AFD-5B3C-456A-82E4-72EE27D26D8D@microsoft.com...
> >> >> >>I need to upload a file to an FTP server, can someone point me to some
> >> >> >>code
> >> >> >> that connects to an FTP server and uploads a file?
> >> >> >>
> >> >> >>
> >> >> >
> >> >> >
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>[/color][/color]
>
>
>[/color]
Juan T. Llibre
Guest
 
Posts: n/a
#15: Apr 28 '06

re: connect to FTP server


re:[color=blue]
>I didn't specify that directory[/color]

Clearly.

That's why I suggested that you *do* specify it.


private void Page_Load(object sender, System.EventArgs e)
{
/*
* Set the "path" variable to the location where files are to be stored
*/
string path = "../docs";

HttpFileCollection files;
files = Page.Request.Files;
for(int index=0; index < files.AllKeys.Length; index++)
{
HttpPostedFile postedFile = files[index];
string fileName = null;
int lastPos = postedFile.FileName.LastIndexOf('\\');
fileName = postedFile.FileName.Substring(++lastPos);
//Check the file type through the extension
if(fileName.EndsWith("doc") || fileName.EndsWith("doc") ||
fileName.EndsWith("pdf") || fileName.EndsWith("pdf")
{
postedFile.SaveAs(MapPath(path + "/" + fileName));
}
}
}



Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"CSharpguy" <CSharpguy@discussions.microsoft.com> wrote in message
news:7759E6DD-C770-4C01-9CA9-C07CDAA88D43@microsoft.com...[color=blue]
>I didn't specify that directory, when I was trying to pull down the file it
> tried and dump it there. I have an upload directory I'm working on pulling
> the files from[/color]
[color=blue]
> "Juan T. Llibre" wrote:[/color]
[color=blue][color=green]
>> re:[color=darkred]
>> > when I try and download a file I get "access denied to c:\windows\system32\ftptest.txt"[/color]
>>
>> You need to specify a directory which isn't security-conscious
>> as the destination for the uploaded files.
>>
>> I'd *never* upload files to that directory.
>>
>> Also, if you're getting "access denied", the account ASP.NET is running as
>> doesn't have enough permissions to access the file and/or directory.
>>
>> Save the following code as "identity.aspx" and run the file.
>>
>> identity.aspx
>> =========
>> <%@ Page Language="VB" %>
>> <%@ Import NameSpace = System.Security.Principal %>
>> <script runat="server">
>> Sub Page_Load()
>> Dim tmp As String = WindowsIdentity.GetCurrent.Name()
>> Label1.Text = tmp
>> End Sub
>> </script>
>> <html>
>> <head>
>> <title>WindowsIdentity.GetCurrent.Name()</title>
>> </head>
>> <body>
>> <form id="form1" runat="server">
>> <div>
>> <asp:Label ID="Label1" Runat="server" Text="Label"></asp:Label>
>> </div>
>> </form>
>> </body>
>> </html>
>> ======
>>
>> Then, assign access permissions for the file/directory to the account which that file returns.
>>
>> Remember to change the upload directory to an ad-hoc directory.
>> Don't use c:\windows\system32\ as your upload directory.
>>
>>
>>
>>
>> Juan T. Llibre, asp.net MVP
>> aspnetfaq.com : http://www.aspnetfaq.com/
>> asp.net faq : http://asp.net.do/faq/
>> foros de asp.net, en español : http://asp.net.do/foros/
>> ===================================
>> "CSharpguy" <CSharpguy@discussions.microsoft.com> wrote in message
>> news:FEFFF6CD-00DE-49AA-B3D6-658E88E31443@microsoft.com...[color=darkred]
>> > I'm using the code and I'm getting 'access denie to file c:\ftptest.txt"
>> > file, or I get False returned. Do i need to do anything on my box other then
>> > the code? I'm logged into the FTP server (via a gui) to see if my file is
>> > getting uploaded and its not, also when I try and download a file I get
>> > "access denied to c:\windows\system32\ftptest.txt"
>> >
>> > whats missing
>> >
>> > "Swanand Mokashi" wrote:
>> >
>> >> The sample code I attached should let you do that.
>> >>
>> >> --
>> >> Swanand Mokashi
>> >> Microsoft Certified Solution Developer (.NET) - Early Achiever
>> >> Microsoft Certified Application Developer (.NET)
>> >>
>> >> http://www.dotnetgenerics.com/
>> >> DotNetGenerics.com -- anything and everything about Microsoft .NET
>> >> technology ...
>> >>
>> >> http://www.swanandmokashi.com/
>> >> http://www.swanandmokashi.com/HomePage/WebServices/
>> >> Home of the Stock Quotes, Quote of the day and Horoscope web services
>> >>
>> >>
>> >> "CSharpguy" <CSharpguy@discussions.microsoft.com> wrote in message
>> >> news:CE5BE3DA-5716-46EF-B01D-522A2085C38C@microsoft.com...
>> >> > I'll consider that as well, but all I need to do realy is upload the file
>> >> > then check to confirm it got there.
>> >> >
>> >> > "Kevin Spencer" wrote:
>> >> >
>> >> >> I might mention that these should be construed as examples. I had to
>> >> >> write
>> >> >> an FTP client, and the Socket connection and related functionality is not
>> >> >> difficult at all. What *is* difficult is handling the various
>> >> >> network-related issues that can arise. For an FTP client to be robust, it
>> >> >> needs to have a lot of recovery functionality (retries, timers, etc)
>> >> >> built
>> >> >> into it.
>> >> >>
>> >> >> Another issue is that some of the format of the returned data, such as
>> >> >> directory listing and system status, is not standardized, and can be
>> >> >> difficult to parse.
>> >> >>
>> >> >> --
>> >> >> HTH,
>> >> >>
>> >> >> Kevin Spencer
>> >> >> Microsoft MVP
>> >> >> Professional Numbskull
>> >> >>
>> >> >> Hard work is a medication for which
>> >> >> there is no placebo.
>> >> >>
>> >> >> "Juan T. Llibre" <nomailreplies@nowhere.com> wrote in message
>> >> >> news:OzMOzjsaGHA.3444@TK2MSFTNGP05.phx.gbl...
>> >> >> > Here's a full-featured, free, FTP Client Library, written in C# :
>> >> >> >
>> >> >> > http://www.c-sharpcorner.com/UploadF...FtpClient.aspx
>> >> >> >
>> >> >> > It's less than 6KB in size.
>> >> >> >
>> >> >> > Here's another example :
>> >> >> > http://www.hotscripts.com/Detailed/40607.html
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > Juan T. Llibre, asp.net MVP
>> >> >> > aspnetfaq.com : http://www.aspnetfaq.com/
>> >> >> > asp.net faq : http://asp.net.do/faq/
>> >> >> > foros de asp.net, en español : http://asp.net.do/foros/
>> >> >> > ===================================
>> >> >> > "CSharpguy" <CSharpguy@discussions.microsoft.com> wrote in message
>> >> >> > news:456D9AFD-5B3C-456A-82E4-72EE27D26D8D@microsoft.com...
>> >> >> >>I need to upload a file to an FTP server, can someone point me to some
>> >> >> >>code
>> >> >> >> that connects to an FTP server and uploads a file?
>> >> >> >>
>> >> >> >>
>> >> >> >
>> >> >> >
>> >> >>
>> >> >>
>> >> >>
>> >>
>> >>
>> >>[/color]
>>
>>
>>[/color][/color]



Kevin Spencer
Guest
 
Posts: n/a
#16: Apr 28 '06

re: connect to FTP server


> I'll consider that as well, but all I need to do realy is upload the file[color=blue]
> then check to confirm it got there.[/color]

To do that, you need to connect your Socket first, wait for a response from
the server, verify the response, send a PASV command to the server, open
your data connection, write the file to the server, close your data
connection, and then wait for a response from the server on your Command
connection.

Any of these can fail over a network, even though they rarely do. That's
what I was talking about. It can be a real nightmare trying to figure out
what went wrong if you don't account for every possibility.

As for your problems with the file upload, be sure that you specify the
absolute file path to your data connection for fetching the file, and a
root-relative path on the server for where you want to upload the file to.
In FTP, the root folder is the "lowest" folder you can access with your
account. This is referred to as "/" in FTP server paths. If you want to
upload the file to a folder underneath that folder, you would add the folder
name after the slash. For example, if the remote folder is:

C:\Inetpub\FtpRoot\folder1

It will be the folder "/" to your client. If you want to upload to

C:\Inetpub\FtpRoot\folder1\subfolder1

Your upload path will be
"/subfolder1/filename.xxx"

So, your command would be: "STOR /subfolder1/filename.xxx" + CRLF

Always be sure to check the response code, the first 3 characters in the
response. It will indicate whether or not the action succeeded. Your app may
not throw any exceptions, but fail to upload the file anyway.
--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

"CSharpguy" <CSharpguy@discussions.microsoft.com> wrote in message
news:CE5BE3DA-5716-46EF-B01D-522A2085C38C@microsoft.com...[color=blue]
> I'll consider that as well, but all I need to do realy is upload the file
> then check to confirm it got there.
>
> "Kevin Spencer" wrote:
>[color=green]
>> I might mention that these should be construed as examples. I had to
>> write
>> an FTP client, and the Socket connection and related functionality is not
>> difficult at all. What *is* difficult is handling the various
>> network-related issues that can arise. For an FTP client to be robust, it
>> needs to have a lot of recovery functionality (retries, timers, etc)
>> built
>> into it.
>>
>> Another issue is that some of the format of the returned data, such as
>> directory listing and system status, is not standardized, and can be
>> difficult to parse.
>>
>> --
>> HTH,
>>
>> Kevin Spencer
>> Microsoft MVP
>> Professional Numbskull
>>
>> Hard work is a medication for which
>> there is no placebo.
>>
>> "Juan T. Llibre" <nomailreplies@nowhere.com> wrote in message
>> news:OzMOzjsaGHA.3444@TK2MSFTNGP05.phx.gbl...[color=darkred]
>> > Here's a full-featured, free, FTP Client Library, written in C# :
>> >
>> > http://www.c-sharpcorner.com/UploadF...FtpClient.aspx
>> >
>> > It's less than 6KB in size.
>> >
>> > Here's another example :
>> > http://www.hotscripts.com/Detailed/40607.html
>> >
>> >
>> >
>> > Juan T. Llibre, asp.net MVP
>> > aspnetfaq.com : http://www.aspnetfaq.com/
>> > asp.net faq : http://asp.net.do/faq/
>> > foros de asp.net, en español : http://asp.net.do/foros/
>> > ===================================
>> > "CSharpguy" <CSharpguy@discussions.microsoft.com> wrote in message
>> > news:456D9AFD-5B3C-456A-82E4-72EE27D26D8D@microsoft.com...
>> >>I need to upload a file to an FTP server, can someone point me to some
>> >>code
>> >> that connects to an FTP server and uploads a file?
>> >>
>> >>
>> >
>> >[/color]
>>
>>
>>[/color][/color]


Closed Thread