attn: gurus?? file to ftp?

i have a file on a desktop that i need to be able to copy to an ftp site....

i have a form and want to click a button that will send it to the site... any direction or links to code that can help.

i found this but cant get it to work..

Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal HINet As Integer) As Integer
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Integer, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Integer) As Integer
Private Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (ByVal hInternetSession As Integer, ByVal sServerName As String, ByVal nServerPort As Integer, ByVal sUsername As String, ByVal sPassword As String, ByVal lService As Integer, ByVal lFlags As Integer, ByVal lContext As Integer) As Integer
Private Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" (ByVal hFtpSession As Integer, ByVal lpszRemoteFile As String, ByVal lpszNewFile As String, ByVal fFailIfExists As Boolean, ByVal dwFlagsAndAttributes As Integer, ByVal dwFlags As Integer, ByVal dwContext As Integer) As Boolean
Private Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" (ByVal hFtpSession As Integer, ByVal lpszLocalFile As String, ByVal lpszRemoteFile As String, ByVal dwFlags As Integer, ByVal dwContext As Integer) As Boolean
Dim INet, INetConn As integer
Dim RC As Boolean
INet = InternetOpen("MyFTP Control", 1, vbNullString, vbNullString, 0)
INetConn = InternetConnect(INet, "";, 0, "yourlogin", "yourpassword", 1, 0, 0)
RC = FtpGetFile(INetConn, "/folder/subfolder/name.ext", "c:\tmp\downloaded.ext", true, 1, 0, 0)
If RC Then "Transfer succesfull!")
InternetCloseHandle INetConn
InternetCloseHandle INet

I did this once, using Sockets and stuff. It's real basic, but it can FTP a file. Shoot me an email if you want and I'll send it to you.

works great but i have one problem... i am doing this with an application and am having a problem.

when it goes to copy the localfile, i get an error because is not authorized to access the file.

is there a way to code around this or will i have to set up permissions through xp to create an account for and assign it permissions.

thanks again for the help...

If the files are always in the same folder, you could give the ASPNET account read access to that folder.

I think you could use impersonation also, but I'm not too familiar with it.

This is very easy with ASP.NET. Just use the HtmlInputFile class.

protected System.Web.UI.WebControls.Button buttonUpload;

protected System.Web.UI.HtmlControls.HtmlInputFile fileUploadControl;


private void buttonUpload_Click(object sender, System.EventArgs e)


    if (null != fileUploadControl.PostedFile)




            + "\" +  System.IO.Path.GetFileName(fileUploadControl.Value));

        Response.Write("<br>File saved bitch<br>");      




<form id="Form1" enctype="multipart/form-data" method="post" runat="server">

      <INPUT id="fileUploadControl" type="file" runat="server">

      <asp:Button id="buttonUpload" runat="server" Text="Upload"></asp:Button>


BTW - I made the assumption that your FTP site is on the same Web server running your ASP.NET app. If not, you can get to the stream behind the file and pull it into a byte array and FTP using the InputStream property of the posted file like this...

byte[] buffer = new byte[fileUploadControl.PostedFile.InputStream.Length];

fileUploadControl.PostedFile.InputStream.Read(buffer, 0, buffer.Length);